Important - When using this code, you must be sure to check the extention type that is being uploaded to the server. We do not allow scripts to be uploaded via asp upload pages. These include .php, .asp, .aspx, .cgi, .js, .vbs, .pl, .exe, or any other script file. Sites found allowing these upload types will be suspended until the proper checks are enabled.
Here is a FAQ for helping you with uploading files using a PHP script.
There are 2 files:
File 1, Select.htm : Source file selection
<HTML>
<BODY BGCOLOR="white">
<FORM METHOD="POST" ACTION="upload.php" ENCTYPE="multipart/form-data">
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" SIZE="100000"><br>
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><br>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</BODY>
</HTML>
The upload.php script uses global variables, $_FILES. File 2, Upload.php : call of the php upload script
<?php
// you must create an 'uploads' directory to upload to
$uploadDir = '/uploads/';
$uploadFile = $uploadDir . basename($_FILES['file1']['name']);
print "<pre>";
// this only allows jpegs to be uploaded
if ($_FILES['file1']['type'] == "image/jpeg") {
if (move_uploaded_file($_FILES['file1']['tmp_name'], $uploadFile))
{
print "File is valid, and was successfully uploaded. ";
}
else
{
print "Error uploading! Here's some debugging info:\n";
print ($_FILES['file1']['error']);
}
} // end if
else {
print "Invalid file type :\n"
}
}
// end if
print "</pre>";
?>
|