By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,091 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,091 IT Pros & Developers. It's quick & easy.

Warning: fopen() [function.fopen]: failed to open stream: No such file or directory

P: 6
i am trying to upload csv file from user's computer to main server
the code i am using is
Expand|Select|Wrap|Line Numbers
  1.  
  2.  if(((isset($_GET['go'])) && ($_GET['going']=="yes")) )
  3.           {
  4.  
  5.             $typefield = $_GET['typefield'];
  6.  
  7.             echo "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"POST\">
  8.                 <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />
  9.                 upload the csv file for $typefield : <input name=\"userfile\" type=\"file\" />
  10.                 <input type=\"hidden\" name=\"updating\" value=\"yes\"/>
  11.                 <input type=\"submit\" name=\"update\" value=\"update\"/>
  12.                 </form>";
  13.  
  14.  
  15.           if((isset($_POST['update'])) ||($_POST['updating']=="yes"))
  16.           {
  17.  
  18.             $typefield = $_GET['typefield'];
  19.  
  20.             echo "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"POST\">
  21.                 <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />
  22.                 upload the csv file for $typefield : <input name=\"userfile\" type=\"file\" />
  23.                 <input type=\"hidden\" name=\"updating\" value=\"yes\"/>
  24.                 <input type=\"submit\" name=\"update\" value=\"update\"/>
  25.                 </form>";
  26.  
  27.  
  28.           if((isset($_POST['update'])) ||($_POST['updating']=="yes"))
  29.           {
  30.  
  31.                 $uploaddir = 'C:\\putcsv\\';
  32.                 $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
  33.  
  34.                 echo '<pre>';
  35.                 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
  36.                 {
  37.                    //echo "Please wait while the database is updated. This may take a few moments depending upon the file size ......";
  38.                 } 
  39.                 else 
  40.                 {
  41.                     echo "Possible file upload attack!\n";
  42.                 }
  43.  
  44.                 //echo 'Here is some more debugging info:';
  45.                 //print_r($_FILES);
  46.                  print "</pre>";
  47.                  $row = 1;
  48.                  $handle = fopen($uploadfile, "r");
  49.                  $colname;
  50.  
  51.                   if($typefield    == "hab")
  52.                             {
  53.  
  54.                                $table = "hab";
  55.                             }
  56.                             else if($typefield    == "resp")
  57.                             {
  58.  
  59.                                $table = "response";
  60.                             }
  61.                             else if($typefield    == "invitation")
  62.                             {
  63.  
  64.                                $table = "invitation";
  65.                             }
  66.                             else if($typefield    == "scr")
  67.                             {
  68.  
  69.                                $table = "screen";
  70.                             }
  71.                             else if($typefield    == "other")
  72.                             {
  73.  
  74.                                $table = "other";
  75.                             }
  76.  
  77.                  $trunc_query = "truncate table $table";
  78.                  dbconnect($trunc_query);
  79.                  //echo $trunc_query;
  80.  
  81.  
  82.                  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
  83.                  {
  84.                       $num = count($data);
  85.  
  86.                           $fullquery = "";
  87.  
  88.                        //$val = $data[$c];
  89.                        if($row==1)
  90.                        {
  91.  
  92.                            //echo $val;
  93.  
  94.  
  95.                        }
  96.                        else
  97.                        {
  98.  
  99.  
  100.  
  101.                             if($typefield    == "hab")
  102.                             {
  103.  
  104.                                $fullquery = "insert into hab(daytime, country, spec, count) values (now(), $data[0], '$data[1]', $data[2]);";
  105.                             }
  106.                             else if($typefield    == "resp")
  107.                             {
  108.  
  109.                                $fullquery = "insert into response(daytime, surveyid, projno, bu, fieldstart,spec, country, status, count) values (now(), $data[0], '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', $data[7]);";
  110.                             }
  111.                             else if($typefield    == "invitation")
  112.                             {
  113.  
  114.                                $fullquery = "insert into invitation(daytime, surveyid, projno, bu, fieldstart,spec, country, count) values (now(), $data[0], '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', $data[6]); ";
  115.                             }
  116.                             else if($typefield    == "screen")
  117.                             {
  118.  
  119.                                $fullquery = "insert into screen(daytime, country, specialty, screenedat, count) values (now(), '$data[0]', '$data[1]', '$data[2]', $data[3]); ";
  120.                             }
  121.                             else if($typefield    == "other")
  122.                             {
  123.  
  124.                                $fullquery = "insert into other(daytime, country, specialty, list, internal, external) values (now(), '$data[0]', '$data[1]', $data[2], $data[3], $data[4]); ";
  125.                             }
  126.  
  127.  
  128.  
  129.                              //echo $fullquery . "<br>";
  130.  
  131.                               if ($fullquery != "")
  132.                               {
  133.  
  134.                                   $result = dbconnect($fullquery);
  135.  
  136.                               }
  137.  
  138.                         }
  139.  
  140.  
  141.  
  142.                    $row++;
  143.                  }
  144.                  echo "<strong>uploaded successfully!</strong>";
  145.  
  146.                  fclose($handle);
  147.  
  148.             }
  149.  
  150.           }
  151.  
  152.  
  153.          }
  154.          else
  155.           echo "You should have admin rights. <a href=\"index.php\">click here</a> to goback to login page please"; 
  156.  
  157.  

i am trying to upload csv file and there is a putcsv folder on the server as well as i am trying it on my machine and i have that folder too.

the errors i am getting are
Expand|Select|Wrap|Line Numbers
  1. Warning: fopen(C:\putcsv\others1.csv) [function.fopen]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\feasibilitytool\upload.php on line 140
  2.  
  3. Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\feasibilitytool\upload.php on line 176
  4.  
  5. Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\feasibilitytool\upload.php on line 176
  6. error|mysql: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , )' at line 1
  7.  
Please help me find out the problem Note :i can't send you complete code above the starting of code ,so code showing 1st line will not be actually 1st line of the code above this is nothing related to upload logic just defining the form
and to make you understand the error pointing out to line
140 is
Expand|Select|Wrap|Line Numbers
  1.  $handle = fopen($uploadfile, "r");
176 is
Expand|Select|Wrap|Line Numbers
  1. while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
and 1st 4 line are
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.      session_start(); 
  3.  
  4.     ?>
Sep 20 '07 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
The file path and name you are generating here does not esist
[PHP]$uploaddir = 'C:\\putcsv\\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);[/PHP]
Sep 21 '07 #2

P: 6
The file path and name you are generating here does not esist
[PHP]$uploaddir = 'C:\\putcsv\\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);[/PHP]

Thanks for your reply but there is a putcsv folder in c directory.
and 1 thing i noticed is its not even uploading the file to this folder"putcsv"
Sep 21 '07 #3

code green
Expert 100+
P: 1,726
there is a putcsv folder in c directory.
I didn't say there wasn't.
Always echo out variables to check what is in there.
[PHP]echo $uploaddir;
echo $uploadfile;[/PHP]Use forward slashes when refering to local directories
Sep 21 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.