简体   繁体   中英

Upload images into folder in different directories php

I am trying to upload images into a folder which is in the different directory with my php files. Currently, my php files are being saved in the testing/admin sides and i wanted to upload my images into the testing/photos. The link in the database which is set manually worked as the images that have been copied into the testing/photos folder can be viewed. But for the uploading part, i tried to set the path as /testing/photos/ but the upload did not work at all. I am using microsoft azure as the server and im not sure how i should set my path for the uploading function.

        move_uploaded_file($_FILES["image"]["tmp_name"],"/testing/photos/" . $_FILES["image"]["name"], $target);

        $location="/testing/photos/" . $_FILES["image"]["name"];
        $type=$_POST['type'];
        $rate=$_POST['rate'];
        $desc=$_POST['desc'];
        $qty=$_POST['qty'];

If your php files are in "testing/admin" folder, and you would like to upload files into "testing/photos" folder, then use this path: ../photos/ . Two dots with slash ../ create path one level up from the folder you are (your php files are) in at the moment.

The second thing I've found in your code is you use three arguments for move_uploaded_file() function while manual describe only two move_uploaded_file($filename, $destination) .

In your code you use three arguments:

  • $_FILES["image"]["tmp_name"] - correct
  • "/testing/photos/" . $_FILES["image"]["name"] "/testing/photos/" . $_FILES["image"]["name"] - no need to use $name, just put path ie ../photos/
  • $target - remove it.

Try this: move_uploaded_file($_FILES["image"]["tmp_name"],"../photos/");

Make sure you use this function in the correct way. More: move_uploaded_file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM