Reputation: 85
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();
}
Upvotes: 1
Views: 427
Reputation: 66
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.
Upvotes: 1
Reputation: 8537
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 !');
}
Upvotes: 0