here is my code.
upload.htm
Code: Select all
<form enctype="multipart/form-data" action="vf.php" method="POST">
<table>
<tr>
<td><input type="hidden" name="MAX_FILE_SIZE" value="30000">
Upload this file: <input name="userfile" type="file">
<input type="submit" value="Upload File"></td>
</tr>
</table>
</form>Code: Select all
<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES
if($_FILESї'userfile']ї'name'] == '') {
echo 'You did not select a photo to upload';
}
elseif($_FILESї'userfile']ї'size'] == 0) {
echo 'There appears to be a problem with the photo your are uploading';
}
elseif($_FILESї'userfile']ї'size'] > $MAX_FILE_SIZE) {
echo 'The photo you selected is too large';
}
elseif(!getimagesize($_FILESї'userfile']ї'tmp_name'])) {
echo 'The photo you selected is not a valid image file';
}
else {
$uploaddir = '/var/www/html/upload/'; // remember the trailing slash!
$uploadfile = $uploaddir. $_FILESї'userfile']ї'name'];
if(move_uploaded_file($_FILESї'userfile']ї'tmp_name'], $uploadfile)) {
echo 'Upload file success!';
}
else {
echo 'There was a problem uploading your file.<br>';
print_r($_FILES);
}
}
?>