简体   繁体   中英

move_uploaded_file not moving

I'm working on a backoffice to uploaded images so you can change the images in the front. Problem is my upload script isn't returning me any errors to work with, but it's also not moving the file. I want my script to upload the new file to that location and replace any file with the same name regardless, but I'd have to get the moving working first.

Where am I going wrong?

================================================================================== EDIT: I've added the slash to the path. It still won't upload my image though. Code is as follows:

$target_path = "../../site/images/user_images/";
$image_name = $_POST['filename'].".".pathinfo($_FILES['file']['name'],PATHINFO_EXTENSION);

if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path.$image_name)) {
    echo "<meta http-equiv='refresh' content='0;URL=images.php?saved=true' />";
} else {
    echo "Error";
}
$target_path = "../../site/images/user_images/";
                                             ^ 

Here you are forgetting / which tells that it is directory where you have to upload the file.

So $target_path.$image_name will become like this

../../site/images/user_images/newfile.png

Else your code produce this output

../../site/images/user_imagesnewfile.png

You're missing the trailing slash. You need:

$target_path = "../../site/images/user_images/";

在路径变量的末尾添加斜杠,然后重试。

$target_path = "../../site/images/user_images/";

have you added enctype in your form?

<form name="form1" id="form1" method="post" action="" enctype="multipart/form-data">
</form>
$target_path = $_SERVER['DOCUMENt_ROOT']."your/folder/relat";

该路径应为完整路径,然后将适当的权限分配给该文件夹

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