473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
3 22010
code green
1,726 Expert 1GB
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
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
1,726 Expert 1GB
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

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

Similar topics

0
by: glesaux | last post by:
Hi, In one of my script i'm trying to apend a daily log file (see script part bellow). When the script runs, this message appears : fopen(temp/pglog.20050106.log): failed to open stream:...
14
by: Aaron Couts | last post by:
I have a program that writes to a log file. It's compiled on RH Linux 7.3 (Kernel 2.4.18-18.7). It's using fopen in append mode. When the file reaches 51200000 bytes in size, the program will no...
3
by: Patrice | last post by:
Hi, I would to call fopen function several time in my application. This application permits to read files which path is registered in a configuration file. For exemple: File 1 = toto.txt File 2...
19
by: lihua | last post by:
Hi, Group! I got one question here: We all know that fclose() must be called after file operations to avoid unexpected errors.But there are really cases when you forget to do that!Just like...
39
by: ferrad | last post by:
I am trying to open a file for appending. ie. if the file exists, open it for appending, if not, create it. I am getting back a NULL pointer, and do not know why. Here is my code: FILE...
10
by: Julia | last post by:
Hi, there, I am trying to append a binary file by using: FILE *strean; stream = fopen( "c:\temp.dat", "ba+" )); Is there a way that I can check if the file exists or not before fopen,...
0
by: milan.topalov | last post by:
I'm having some strange problems using fopen() to fetch website content. It seems I can't open URL shorter then certain lenght. I can open this:...
5
by: Brian | last post by:
Hi I have a problem in opening url using 'file'. I searched many other discussion groups and tried suggestions, but could not resolve this problem. e.g <?php $myfile =...
5
by: phpnewbie26 | last post by:
I've been having trouble trying to open a file. It outputs fopen(/projects/CCPROT/ts_classes) : failed to open stream: No such file or directory in /mnt/raid/www/intra/admin/ts2/test2.php on line 72...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.