繁体   English   中英

无法将文件移动到php中的文件夹

[英]Not able to move file into folder in php

我无法将文件移到所需的文件夹中。 我想将图像保存到上传的文件夹中。 在MySQL中,我在blob类型。 这是我的代码

$target_Path = "uploaded/";
    $target_Path = $target_Path.basename( $_FILES['image']['name'] );
    move_uploaded_file( $_FILES['image']['tmp_name'], $target_Path );

    mysqli_query($con,"UPDATE info SET photo='$target_Path' WHERE user_id='$id'");

在mysql中,它表明已保存了一些内容,但未打开,并且文件未移入上载的文件夹。 我正在我的本地主机中执行此操作。 请帮忙。

尝试使用IF语句包装move_uploaded_file,如果文件传输失败,则引发异常:

if (move_uploaded_file($_FILES['image']['tmp_name'], $target_Path ) === false) {
    throw new Exception([text]);
}

另外,要测试目标是否可写,可以尝试在该处打开一个文件并写入该文件:

if (($fp = fopen($target_path, 'w')) === false) {
    thrown new Exception("Failed to open file $target_path for writing");
}
fwrite($fp, file_get_contents($_FILES['image']['tmp_name']));
fclose($fp);

问题可能是文件权限或所有权之一,您需要使用chmod或chown在命令行中进行修复。

暂无
暂无

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

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