简体   繁体   中英

move_uploaded_file warning

I am encountering the following error message saying:

Warning: move_uploaded_file(uploads/computer-science1.jpg): failed to open stream: No such file or directory....

while trying to move a file to a directory. above code provided. I have also enabled the uploaded file in FileZilla to be writable and executable, is there another way of solving particular problem? Thank you.

<?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();
   }

Your PHP script must be in a directory which contains a sub-directory, uploads/ , which is writeable.

It seems as if you are attempting to move the file from its temporary location to a folder ( uploads/ ) that either doesn't exist or that the script is unable to write to.

When you've got this message :

Warning: move_uploaded_file(uploads/computer-science1.jpg): failed to open stream: No such file or directory....

It means that the location of the file or the location of the destination directory is not good. Maybe you can check your link path of "uploads/computer-science1.jpg"

You can use a test to check it :

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

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