Reputation: 2464
I am attempting to upload a file using an HTML form and php, the code goes like this:
$targetPictureLocation = "/files/images/team/" . strtolower(str_replace(" ","", $_POST['name'])) . ".png";
move_uploaded_file($_FILES['file']['tmp_name'], $targetPictureLocation);
Now I believe the $targetPictureLocation
refrences www.domain.com/targetpath/
because there is a slash infront of files. Is this proper? If so then the directory does exist however I am getting these errors:
Warning: move_uploaded_file(/files/images/team/foobar.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/08/11798508/html/domainname/files/scripts/userManagement.php on line 259
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpwzO4X7' to '/files/images/team/foobar.png' in /home/content/08/11798508/html/domainname/files/scripts/userManagement.php on line 259
What am I doing wrong?
Thank you so much
Upvotes: 0
Views: 546
Reputation: 3563
Try :
$targetPictureLocation = $_SERVER['DOCUMENT_ROOT']."/domainname/files/images/team/" . strtolower(str_replace(" ","", $_POST['name'])) . ".png";`
You are only adding the relative path which will point PHP to :
/home/content/08/11798508/html/domainname/files/scripts/files/images/team/
which is the wrong location. PHP's $_SERVER['DOCUMENT_ROOT']
will return the scripts' base directory URL. Since the folder you want to upload is in the parent folder. You should use $_SERVER['DOCUMENT_ROOT']
and the location becomes :
/home/content/08/11798508/html/domainname/files/images/team/
Upvotes: 1