Upload problem
Posted: Fri May 26, 2006 12:03 pm
Hi there, I am trying to let people upload images onto my site and have the following HTML and PHP, there error i seem to be getting is this:
Here is the HTML:
The PHP is here:
Anyone got any ideas?
Thanks in advance... Tom
Code: Select all
Warning: move_uploaded_file(/uploads/amazon-logo-151x32.gif): failed to open stream: No such file or directory in /home/tom10001/public_html/496/uploadtest.php on line 44
Warning: move_uploaded_file(): Unable to move '/tmp/phpyBtSUZ' to '/uploads/amazon-logo-151x32.gif' in /home/tom10001/public_html/496/uploadtest.php on line 44
Problem: Could not move file to destination directoryCode: Select all
<html>
<head>
<title>Upload images</title>
</head>
<body>
<h1>Upload files</h1>
<form enctype="multipart/form-data" action="uploadtest.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
Upload this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
</body>
</html>Code: Select all
<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>
<?php
// $userfile is where the 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 e.g. image/gif
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
// $userfile_error is any error encountered
$userfile_error= $HTTP_POST_FILES['userfile']['error'];
if($userfile_error > 0)
{
echo 'Problem: ';
switch ($userfile_error)
{
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
// Does the file have the correct mime type?
if($userfile_type != 'image/gif')
{
echo 'Problem: file is not a GIF';
exit;
}
$upfile = '/uploads/'.$userfile_name;
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;
}
echo 'File uploaded successfully<br/><br/>';
//reformat file contents
$fp = fopen($upfile,'r');
$contents = fread($fp, filesize ($upfile));
fclose($fp);
$contents = strip_tags($contents);
$fp = fopen($upfile, 'w');
fwrite($fp, $contents);
fclose($fp);
?>
</body>
</html>Thanks in advance... Tom