简体   繁体   中英

PHP move_uploaded_file doesn't work

I'm using HTTP post to upload image to server and I have the following PHP code:

$base_path = "";
$target_path = $base_path . basename ( $_FILES ['uploadfile'] ['name'] );
if (move_uploaded_file ( $_FILES ['uploadfile'] ['tmp_name'], $target_path )) {
    echo "Good";
} else {
    echo "FAIL";
}

I'm sure the image has been uploaded to temp. But no matter what, I just can't store image file. my current permission is 664 for testing.

You need to set your $base_path variable to an absolute path to where you are storing the file. ( ie. /path/to/your/document/root/image/directory/ )

Additionally, make sure the directory you will be storing the images in is either owned by the apache user or that it is writable by the apache user (chmod 777).

Try this:

Pl check the uploaded path is correct before move the file

&&

Set the folder permission to 777 where you upload the file.

Thanks!

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