<html>
<head>
<title>Zachs Page</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload_image.php" method="post">
<input type="hidden" name="MAX_SIZE" size="524288">
<p>
File:<input type="file" name="upload"/></p>
<input type="submit" name="submit" value="submit"/>
<input type="hidden" name="submitted" value="TRUE"/>
</form>
<?php
if(isset($_POST['submitted']))
{
if(isset($_FILES['upload']))
{
$allowed= array('image/pjpeg',
'image/jpeg', 'image/jpeg',
'image/JPG', 'image/X-PNG',
'image/PNG', 'image/png',
'image/x-png');
if(in_array($_FILES['upload']['type'],$allowed))
{
if(move_uploaded_file($_FILES['upload']['tmp_name'] , "/MyFiles/{$_FILES['upload']['name']
}"))
{
echo "The File has been uploaded";
}
else
{
echo "Please upload a proper type.";
}
}
}
if($_FILES['upload']['error']>0)
{
switch($_FILES['upload']['error']){
case 1:
print 'the files exceeds max upload size setting in php.ini';
break;
case 2:
print 'Exceeds MAX_FILE_SIZE in html form';
break;
case 3:
print'The file was only partially uploaded';
break;
case 4:
print 'The file was not uploaded';
break;
case 6:
print 'No temp_file was available';
break;
case 7:
print 'Unable to write to disk';
break;
case 8:
print 'The file upload was stopped';
default:
print 'A system error has occured';
break;
}
}
if(file_exists($_FILES['upload']['tmp_name']&& is_file($_FILES['upload']['tmp_name'])))
{
unlink
($_FILES['upload']['tmp_name']);
}
}
?>
</body>
</html>
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.