move_uploaded_file警告

时间:2016-03-12 17:51:27

标签: php

我遇到以下错误消息:

Warning: move_uploaded_file(uploads/computer-science1.jpg): failed to open stream: No such file or directory....
尝试将文件移动到目录时

。以上代码提供。 我还启用了FileZilla中的上传文件可写和可执行,还有另一种解决特定问题的方法吗? 谢谢。

<?php
$upload_url = "uploads/" . $_FILES["myfile"]["name"];

$filename = $_FILES["myfile"]["name"];

move_uploaded_file($_FILES["myfile"]["tmp_name"], $upload_url);

$conn = mysqli_connect("yourhost", "username", "password", "databasename");

$sql = "INSERT INTO images (image_url, image_title) VALUES     ('$upload_url','$filename') ";

$imageresults = mysqli_query( $conn,$sql );

$sql = "SELECT image_url, image_title from images";

if ($imageresults = mysqli_query( $conn, $sql )) {

while ( $currentimage = mysqli_fetch_assoc($imageresults ) ) {

echo "<div><img src= '" . $currentimage['image_url'] . "'  

                        width='200' height='200'/><br/>" .

$currentimage['image_title']  . "</div>";

}

}

} catch( Exception $e ) {
echo $e->getMessage();
   }

2 个答案:

答案 0 :(得分:1)

您的PHP脚本必须位于包含子目录uploads/的目录中,该目录是可写的。

好像您正试图将文件从其临时位置移动到文件夹(uploads/),该文件夹不存在或脚本无法写入。

答案 1 :(得分:0)

当您收到此消息时:

  

警告:move_uploaded_file(uploads / computer-science1.jpg):失败了   open stream:没有这样的文件或目录......

这意味着文件的位置或目标目录的位置不好。也许您可以查看&#34; uploads / computer-science1.jpg&#34;

的链接路径

您可以使用测试来检查它:

if(move_uploaded_file($yourFile, $yourlocation)) {
    echo 'Good ! ';
} else {
    exit('Error !');
}