Upload script having difficulties uploading to a certain location not in proximity, how can I resolve?

fsofb Source

This script is designed to upload a photo to a targeted folder call photos. I can't find any working method to resolve this. None of the solutions on this site are not working for me and I can't find a working solution on google.

so the file call submit-a-new-photo.php is located at C:/xampp/htdocs/zoo-library/animals/submit-a-new-photo.php

and the photos folder is located at C:/xampp/htdocs/wild-life/animals/photos

and when I try to upload a photo I get these errors

Warning: move_uploaded_file(/wild-life/animals/photos/fox.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\zoo-library\animals\submit-a-new-photo.php on line 14

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php93B4.tmp' to '/wild-life/animals/photos/fox.jpg' in C:\xampp\htdocs\zoo-library\animals\submit-a-new-photo.php on line 14

This is my code

submit-a-new-photo.php

<form action='' method='post' enctype='multipart/form-data'>

<input type='file' name='file'><br>
<input type='submit' name='submit' value='upload'>

</form>

<?php

if(isset($_POST['submit'])){

$file=$_FILES['file']['name'];
$location='/wild-life/animals/photos/'.$file;
move_uploaded_file($_FILES['file']['tmp_name'],$location);  

}

?>
php

Answers

answered 1 week ago Barmar #1

You didn't put the complete path in $location. It should be:

$location = 'C:/xampp/htdocs/wild-life/animals/photos/' . $file;

If you don't want to hard-code C:/xampp/htdocs, you can use the $_SERVER variable that holds this automatically.

$location = $_SERVER['DOCUMENT_ROOT'] .'/wild-life/animals/photos/' . $file;

comments powered by Disqus