<title>Zachs Page</title>

<form enctype="multipart/form-data" action="upload_image.php" method="post">
<input type="hidden" name="MAX_SIZE" size="524288">
File:<input type="file" name="upload"/></p>
<input type="submit" name="submit" value="submit"/>
<input type="hidden" name="submitted" value="TRUE"/>




$allowed= array('image/pjpeg',
'image/jpeg', 'image/jpeg',
'image/JPG', 'image/X-PNG',
'image/PNG', 'image/png',
if(move_uploaded_file($_FILES['upload']['tmp_name'] , "/MyFiles/{$_FILES['upload']['name']

echo "The File has been uploaded";
echo "Please upload a proper type.";





case 1:
print 'the files exceeds max upload size setting in php.ini';
case 2:
print 'Exceeds MAX_FILE_SIZE in html form';
case 3:
print'The file was only partially uploaded';
case 4:
print 'The file was not uploaded';
case 6:
print 'No temp_file was available';
case 7:
print 'Unable to write to disk';
case 8:
print 'The file upload was stopped';
print 'A system error has occured';

if(file_exists($_FILES['upload']['tmp_name']&& is_file($_FILES['upload']['tmp_name'])))


I have used a similar template before from Visual Quick Pro Guide and had no errors with this. But whenever I try to upload an image (that is quite small) I get

       Warning: move_uploaded_file(/MyFiles/4.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\MyFiles\upload_image.php on line 31

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php1B3E.tmp' to '/MyFiles/4.jpg' in C:\xampp\htdocs\MyFiles\upload_image.php on line 31
Please upload a proper type.

Now I am kinda confused. I have a file that I have uploaded, and if I remove $_FILES['upload']['name'] it said it uploaded, even though no file is there. I have tried for hours straight to get this but I don't see any difference between my example and the book's.

You need to provide the full file system path. So intead of "/MyFiles/4.jpg" use "C:/xampp/htdocs/MyFiles/4.jpg". I suggest you try:

if(move_uploaded_file($_FILES['upload']['tmp_name'] , $_SERVER['DOCUMENT_ROOT'] . "/MyFiles/{$_FILES['upload']['name']
Member Avatar


Carrying on from johnny1 - PHP file functions can access locations above the public root, so prefixing locations with '/' means that you are probably referring to - if using Windows - C:\
So, PHP is looking for C:\MyFiles, which probably doesn't exist. If you are saving to a location above the public root then you can use relative prefixes like ../../secretfiles/MyFiles etc - you can also use relative locations within the public directories - you do not have to use $_SERVER['DOCUMENT_ROOT'].

It appears that your file uploader script: upload_image.php is the "view" and the handler all in one. Not usually the way to do it, but anyway, as this file is within the a public directory - I'm assuming public root, you should be able to store it just by the following:

if(move_uploaded_file($_FILES['upload']['tmp_name'] , "MyFiles/{$_FILES['upload']['name']}"))...

Again assuming that the MyFiles directory is in the same parent directory as the upload_image.php file.