php move_uploaded_file()图像权限问题

时间:2016-06-21 16:35:23

标签: php html mysql

我的代码成功处理上传图片。但问题是它无法显示上传的图像。我检查图像路径输出在html源视图中是正确的但图像直到不显示。我认为它是一个文件权限问题。如何使用读写完全权限上传这些图像,以便正确显示图像。

if(isset($_POST["submit_img"])) {
$target_dir = "../assets/img/temp_img/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$randstr = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 3);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],$target_dir.$randstr)) 
{

    $q =mysqli_query($conn,"INSERT INTO temp_img (product_img_url) VALUES ('$randstr')");
    if ($q>0) {
      echo "<br>The file has been uploaded.";
    }
} else {echo "<br>Error uploading your file.";}
}
//show all uploaded images
$q2 = mysqli_query($conn,"SELECT product_img_url FROM temp_img");

while ($row = mysqli_fetch_array($q2)) {
    $product_img_url = $row['product_img_url'];
    $img_format = ".jpg";
    $broken_url = "assets/img/temp_img/";


echo '<img src="'.$main_url.$broken_url.$product_img_url.$img_format.'" class="img-rounded" alt="Cinque Terre" width="304" height="236">';

}

image missing picture

1 个答案:

答案 0 :(得分:0)

我认为以下链接可以帮助您更改文件的权限。

http://php.net/manual/en/function.chmod.php

注意:  1.检查上传的文件是否在指定的文件夹中。

2.设置路径没有&#34; ../"在变量 targetdir