Reputation: 23
I keep on getting these warnings when i try to upload images to my directory:
Warning: move_uploaded_file(localhost/school/photo/IMG_3036.PNG): failed to open stream: No such file or directory in C:\xampp\htdocs\school\Pages\upload.php on line 20
Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpDE6A.tmp' to 'localhost/school/photo/IMG_3036.PNG' in C:\xampp\htdocs\school\Pages\upload.php on line 20
CODE:
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="upload" /> <input type="submit" name="btn_upload" value="UPLOAD" />
</form>
<?php
if (isset($_POST['btn_upload']))
{
$filetmp = $_FILES["upload"]["tmp_name"];
$filename = $_FILES["upload"]["name"];
$filetype = $_FILES["upload"]["type"];
$filepath = "localhost/school/photo/".$filename;
move_uploaded_file($filetmp,$filepath); //LINE 20
$con = mysqli_connect ("localhost" , "web" , "" , "imagestore") or die ("could not connect");
$sql = "INSERT INTO upload_img (img_name,img_path,img_type) VALUES ('$filename','$filepath','$filetype')";
$result = mysqli_query($con,$sql) or die("error");
}
?>
HERES my directory,
c:xammp\htdocs\school\photo
Upvotes: 2
Views: 2590
Reputation: 19573
move_uploaded_file
requires a filesystem path, not a url
path, as the destination. you are passing a url path. assuming you have permission to write to the folder, setting a correct $filepath
should work:
$filepath = "C:\\xampp\\htdocs\\school\\photo\\".$filename;
since that is the actual path on your computer to the photos directory.
Upvotes: 0