fra php til asp
Hej har fundet en upload funktion som oploader via flash desværre erden source code som der bruges php så er der nogen der kan hjælpe med at oversætte php coden til asp/vbscript coden er :
/*
<?php
foreach ($_FILES as $fieldName => $file) {
//$filenames .= $fieldName. "\n";
move_uploaded_file($file['tmp_name'], "./images/" . $file['name']);
}
echo true;
//file_put_contents('filenames.txt', $filenames);
?>
*/
<?php
$MAXIMUM_FILESIZE = 1024 * 400; // 200KB
$MAXIMUM_FILE_COUNT = 1000; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temporary/".$_FILES['Filedata']['name']);
$type = exif_imagetype("./temporary/".$_FILES['Filedata']['name']);
if ($type == 1 || $type == 2 || $type == 3) {
rename("./temporary/".$_FILES['Filedata']['name'], "./images/".$_FILES['Filedata']['name']);
} else {
unlink("./temporary/".$_FILES['Filedata']['name']);
}
}
$directory = opendir('./images/');
$files = array();
while ($file = readdir($directory)) {
array_push($files, array('./images/'.$file, filectime('./images/'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
$files_to_delete = array_splice($files, 0, count($files) - $MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++) {
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);
function sorter($a, $b) {
if ($a[1] == $b[1]) {
return 0;
} else {
return ($a[1] < $b[1]) ? -1 : 1;
}
}
?>
serveren hvor asp scriptet skal køre er der aspSmartUpload så en normal html og asp upload code ser sådan her ud:
Html:
<HTML>
<BODY BGCOLOR="white">
<H1>aspSmartUpload : Sample 1</H1>
<HR>
<FORM METHOD="POST" ACTION="/scripts/aspSmartUpload/Sample1.asp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</BODY>
</HTML>
Asp coden
<%
' Variables
' *********
Dim mySmartUpload
Dim intCount
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload
' ******
mySmartUpload.Upload
' Save the files with their original names in a virtual path of the web server
' ****************************************************************************
intCount = mySmartUpload.Save("/aspSmartUpload/Upload")
' sample with a physical path
' intCount = mySmartUpload.Save("c:\temp\")
' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.")
%>
