strom
strom

Reputation: 7

Failed to open stream when uploading image to server

I'm uploading an image image to my server. I'm using the following script:

<?php
include("mysqlconnect.php");

    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }
     
     
     
if (!empty($_FILES["uploadedimage"]["name"])) {

    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ext = GetImageExtension($imgtype);
    $imagename=date("d-m-Y")."-".time().$ext;
    $target_path = "images/".$imagename;
    

if(move_uploaded_file($temp_name, $target_path)) {

    $query_upload="INSERT into 'images_tbl' ('images_path','submission_date') VALUES ('".$target_path."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());  
    
}else{

   exit("Error While uploading image on the server");
} 

}

?>

I'm having some issues with my code. I'm getting multiple errors.

failed to open stream: No such file or directory in C:\xampp\htdocs\nipu\file upload\saveimage.php on line 29

Warning: move_uploaded_file(images/03-05-2016-1462289806.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\nipu\file upload\saveimage.php on line 29

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpF912.tmp' to 'images/03-05-2016-1462289806.jpg' in C:\xampp\htdocs\nipu\file upload\saveimage.php on line 29

What's the problem here?

Upvotes: 1

Views: 2158

Answers (2)

Dipanwita Kundu
Dipanwita Kundu

Reputation: 1667

  1. set full path $target_path
  2. Check the destination folder is exist or not?
  3. Set 'write' permission for that folder also.

Upvotes: 1

Anand Parmar
Anand Parmar

Reputation: 168

According to your code your directory structure like this

-nipu
--file upload
---saveimage.php
---images

Upvotes: 0

Related Questions