I’m trying to upload files (images) with this PHP script and I’m getting errors. Yes, I know that there are other questions on here that ask the same thing, but I didn’t find any of them usefull.
Here’s my script (the short version):
//*** FILE IS NAMED 'imageUpload' IN THE INC FOLDER ***
$image_name = addslashes($_FILES['image']['name']);
$image_tmpName = $_FILES['image']['tmp_name'];
$location = "usr/profile/$image_name";
move_uploaded_file($image_tmpName,'../img/'.$location);
Here’s my file tree (CAPITOLS-folders , lower-file):
1. IMG
-USR
*PROFILE
2. INC
-imageUpload.php
The errors that I’m getting:
Warning: move_uploaded_file(../img/usr/profile/Cheese.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/35/9611635/html/chsyearbook/inc/imageUpload.php on line 12
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpuLkkjE' to '../img/usr/profile/Cheese.jpg' in /home/content/35/9611635/html/chsyearbook/inc/imageUpload.php on line 12
Now these errors are clearly saying that the directory doesn’t exist, but I assur you, I’m looking at it right now.
I think this might be a problem with the PHP.ini file. if so, here’s the PHP.ini (why not, eh?)
max_execution_time = 60;
memory_limit = 256M;
upload_max_filesize = 256M;
post_max_size = 256M;
There are some comments on the php manual page for the function that suggest using a relative path here does not work as expected.
https://www.php.net/move_uploaded_file
[edit]
try checking the working directory with the
getcwd()function before calling move_uploaded_file. This should tell you what directory the relative path is… relative to.