[function.copy]: failed to open stream: No such file or dire

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chin
Forum Newbie
Posts: 3
Joined: Tue Apr 05, 2011 8:29 am

[function.copy]: failed to open stream: No such file or dire

Post by chin »

Still uploading picture.Last time i thought the problems was declaration $file but just now i put some code to echo the picture.then the other error was shown
***error:[function.copy]: failed to open stream: No such file or directory in...
i saw the other suggest using trim(),but i familier with...

album.php-part of code without connection function

Code: Select all

# <form action="submit.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return requiredCheck(this);">
# <table><td>
#   <tr><input name="file" type="file" id="file" 
#       class="txt_blacknormal" size="40" /></tr>
# </td>
# <td><tr> <input name="Submit" type="submit" value="Submit" /></tr></td></table>
# <form>

submit.php

Code: Select all

   1. <?php
   2. include "session.php";
   3. include "function.php";
   4. $admincate = new Admincate;
   5.  
   6. if (@$_POST['Submit'] == "Submit")
   7. {    
   8.     $cname =$_POST['cname'];
   9.     $cdesc=$_POST['cdesc'];
  10.    $file=$_FILES['file']['file_name'];
  11.  
  12.     $info =$cname;
  13.      $id2 = session_id();
  14.     $ip_address =  "$_SERVER[REMOTE_ADDR]"; 
  15.     session_register("info");
  16.     if (!$admincate->checkCate($cname))
  17.         {
  18.             header("Location: albumnew.php?m=ext");                        
  19.         }
  20.         else{
  21.  
  22.             $cid = $admincate->getNewID('c','cid','category');
                    $target_path = "albumpic/";
                    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

                    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                    echo "The file ".  basename( $_FILES['uploadedfile']['name']).  " has been uploaded";} 
			else{
                    echo "There was an error uploading the file, please try again!";
                  }
  23.             if ($admincate->addCate($cid,$cname,$cdesc,$file,$file_name))
  24.             {
  25.                 session_unregister("info");
  26.  
  27.                 header("Location: albumreview.php?cid=$cid");    
  28.  
  29.             }
  30.             else
  31.             {
  32.                 echo "<SCRIPT>alert(\"Database Error! Unable to add data into database!\");history.go(-1)</SCRIPT>";
  33.             }
  34.         }
  35.  
  36. }
  37. ?>

function.php

Code: Select all


   1. <?
   2. include "admin_connectDB.php";
   3. class admincate{
   4. function addCate($cid,$cname,$cdesc,$file,$file_name)
   5.     {
   6.     if($file!='' && $file!='none')
   7.         {
   8.             $path = "../albumpic/$file_name"; 
   9.             $query = "SELECT cpic FROM category WHERE cpic = '$path'";
  10.             $result = mysql_query($query);
  11.             if(mysql_num_rows($result)!=0)
  12.             {
  13.                 $file_path = $this->generate_num('albumpic',$file_name,'cpic','category');
  14.                 $path = "../albumpic/$file_path";
  15.             }
  16.             copy($file, $path);
  17.  
  18.         }
  19.         else
  20.         {
  21.             $path = "";
  22.         }            
  23.         $query1 = "INSERT INTO category  VALUES('','$cid','$cname','$cdesc','$path','','','')";
  24.         $result1 = mysql_query($query1);
  25.         if ($result1)
  26.         return true;
  27.         else
  28.         return false;
  29.     }
  30. }
  31. ?>
  32.  

Last edited by chin on Sat Apr 09, 2011 12:59 am, edited 3 times in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: how to declare the uploaded picture on submition page

Post by social_experiment »

Your one lined question is a bit vague so i will reply to what i think you are refering to

Code: Select all

$file1=$_POST['file'];
// should be
$file1 = $_FILES['file']['name'];
This will give you the filename.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to declare the uploaded picture on submition page

Post by fugix »

yes please let us know exactly what your question is so we may help you to find a solution
chin
Forum Newbie
Posts: 3
Joined: Tue Apr 05, 2011 8:29 am

Re: how to declare the uploaded picture on submition page

Post by chin »

i'm so sorry .I supposed state my problem in details.My problem was all of the data already inserted into the database but except the uploaded picture.I found that maybe was the posting picture info to submit.php unsuccessfully.
This is my added category function /*addCate($cid,$cname,$cdesc,$file,$file_name).*/$file and $file_name are fields of the picture .
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: how to declare the uploaded picture on submition page

Post by social_experiment »

chin wrote:My problem was all of the data already inserted into the database but except the uploaded picture
Most likely due to the fact that you accessed the file name incorrectly. Tip : $_FILES['file']['name']
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: how to declare the uploaded picture on submition page

Post by fugix »

did changing $_POST to $_FILES work for you?
chin
Forum Newbie
Posts: 3
Joined: Tue Apr 05, 2011 8:29 am

Re:how to declare the uploaded pic on submition page

Post by chin »

ya ya....because i thought there was declaration problems so i keep changing that part then i don't realise i post the wrong version on here.So sorry but thanks for who helping me and correct it.
Post Reply