Forum Moderators: coopster
<form ENCTYPE="multipart/form-data" METHOD="post" ACTION='sendfile.php'>
<input type="hidden" name="MAX_FILE_SIZE" value="10000">
<input id='uploadName' name='fileName' type='file'>
<input type='submit'>
</form>
for the form and for the sendfile.php,:
<?php
$maxSize=300000; // Only save files smaller than 300k
$uploadSize = $_FILES['fileName']['size']; // The size of our uploaded file
$uploadType = $_FILES['fileName']['type']; // The type of the file.
if ($uploadSize<$maxSize) { // Make sure the file size isn't too big.
move_uploaded_file($_FILES['fileName'] ); // save file.
echo "File saved as <BR>";
echo "It was $uploadSize bytes of type $uploadType";
} else {
echo "File not saved. It's too big! Max filesize is $maxSize";
}
?>
My problem is I can't figure out how to have it keep the original file name. I know this is a total beginner question and thanks!
When you upload files via the $_FILES array, your information would be collected like this:
$_FILES['fileName']['name'] = Name of File
$_FILES['fileName']['tmp_name'] = Temporary File
$_FILES['fileName']['size'] = Size of File
$_FILES['fileName']['type'] = File Type
Try using the following code to echo your $_FILES array to give you a better understanding:
echo '<pre>';
print_r($_FILES);
echo '</pre>';
You`ll need to change this line:
move_uploaded_file($_FILES['fileName']);
to something like this:
move_uploaded_file($_FILES['fileName']['tmp_name'],$_FILES['fileName']['name']);
You should also use is_uploaded_file [php.net] to check if the temporary file got uploaded before you attempt to move it.
For more information see:
[php.net...]
dc