Hi,
I am using common php script which can upload files to a folder on my webspace. I have almost got it to work however, the uploaded files are not recognised by the server or browser as anything other than text. For example, I upload an image such as cloud.gif - the script saves it as cloud.gif in the folder but my FTP software and browser treat it like text. Do you have any suggestions?
The script for uploading is:
Here is the form script:
<form enctype="multipart/form-data" action="image_upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">
<input name="userfile" type="file">
<input type="submit" value="Send File" >
</form>
Here is the image_upload.php:
// $userfile is where file went on webserver
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
// $userfile_name is original file name
$userfile_name = $HTTP_POST_FILES['userfile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
// $userfile_type is mime type
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['userfile']['error'];
if ($userfile=='none')
{
echo 'Problem: no file uploaded';
exit;
}
if ($userfile_size==0)
{
echo 'Problem: uploaded file is zero length';
exit;
}
// location of file to be moved
$upfile = '/home/mysiteuk/public_html/myfolder/'.$userfile_name.' ';
// is_uploaded_file and move_uploaded_file
if (is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
exit;
}
Thanks,
Jimbob