简体   繁体   English

move_uploaded_file不动

[英]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 所以$target_path.$image_name会变成这样

../../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? 您在表单中添加了enctype吗?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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