Warning: fopen() [function.fopen]: failed to open stream: No such file or directory | Newbie | | Join Date: Sep 2007
Posts: 6
| |
i am trying to upload csv file from user's computer to main server
the code i am using is -
-
if(((isset($_GET['go'])) && ($_GET['going']=="yes")) )
-
{
-
-
$typefield = $_GET['typefield'];
-
-
echo "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"POST\">
-
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />
-
upload the csv file for $typefield : <input name=\"userfile\" type=\"file\" />
-
<input type=\"hidden\" name=\"updating\" value=\"yes\"/>
-
<input type=\"submit\" name=\"update\" value=\"update\"/>
-
</form>";
-
-
-
if((isset($_POST['update'])) ||($_POST['updating']=="yes"))
-
{
-
-
$typefield = $_GET['typefield'];
-
-
echo "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"POST\">
-
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"30000\" />
-
upload the csv file for $typefield : <input name=\"userfile\" type=\"file\" />
-
<input type=\"hidden\" name=\"updating\" value=\"yes\"/>
-
<input type=\"submit\" name=\"update\" value=\"update\"/>
-
</form>";
-
-
-
if((isset($_POST['update'])) ||($_POST['updating']=="yes"))
-
{
-
-
$uploaddir = 'C:\\putcsv\\';
-
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
-
-
echo '<pre>';
-
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
-
{
-
//echo "Please wait while the database is updated. This may take a few moments depending upon the file size ......";
-
}
-
else
-
{
-
echo "Possible file upload attack!\n";
-
}
-
-
//echo 'Here is some more debugging info:';
-
//print_r($_FILES);
-
print "</pre>";
-
$row = 1;
-
$handle = fopen($uploadfile, "r");
-
$colname;
-
-
if($typefield == "hab")
-
{
-
-
$table = "hab";
-
}
-
else if($typefield == "resp")
-
{
-
-
$table = "response";
-
}
-
else if($typefield == "invitation")
-
{
-
-
$table = "invitation";
-
}
-
else if($typefield == "scr")
-
{
-
-
$table = "screen";
-
}
-
else if($typefield == "other")
-
{
-
-
$table = "other";
-
}
-
-
$trunc_query = "truncate table $table";
-
dbconnect($trunc_query);
-
//echo $trunc_query;
-
-
-
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
-
{
-
$num = count($data);
-
-
$fullquery = "";
-
-
//$val = $data[$c];
-
if($row==1)
-
{
-
-
//echo $val;
-
-
-
}
-
else
-
{
-
-
-
-
if($typefield == "hab")
-
{
-
-
$fullquery = "insert into hab(daytime, country, spec, count) values (now(), $data[0], '$data[1]', $data[2]);";
-
}
-
else if($typefield == "resp")
-
{
-
-
$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]);";
-
}
-
else if($typefield == "invitation")
-
{
-
-
$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]); ";
-
}
-
else if($typefield == "screen")
-
{
-
-
$fullquery = "insert into screen(daytime, country, specialty, screenedat, count) values (now(), '$data[0]', '$data[1]', '$data[2]', $data[3]); ";
-
}
-
else if($typefield == "other")
-
{
-
-
$fullquery = "insert into other(daytime, country, specialty, list, internal, external) values (now(), '$data[0]', '$data[1]', $data[2], $data[3], $data[4]); ";
-
}
-
-
-
-
//echo $fullquery . "<br>";
-
-
if ($fullquery != "")
-
{
-
-
$result = dbconnect($fullquery);
-
-
}
-
-
}
-
-
-
-
$row++;
-
}
-
echo "<strong>uploaded successfully!</strong>";
-
-
fclose($handle);
-
-
}
-
-
}
-
-
-
}
-
else
-
echo "You should have admin rights. <a href=\"index.php\">click here</a> to goback to login page please";
-
-
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 -
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
-
-
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\feasibilitytool\upload.php on line 176
-
-
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\feasibilitytool\upload.php on line 176
-
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
-
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 - $handle = fopen($uploadfile, "r");
176 is - while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
and 1st 4 line are - <?php
-
session_start();
-
-
?>
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,076
| | | re: Warning: fopen() [function.fopen]: failed to open stream: No such file or directory
The file path and name you are generating here does not esist
[PHP]$uploaddir = 'C:\\putcsv\\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);[/PHP]
| | Newbie | | Join Date: Sep 2007
Posts: 6
| | | re: Warning: fopen() [function.fopen]: failed to open stream: No such file or directory Quote:
Originally Posted by code green 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"
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,076
| | | re: Warning: fopen() [function.fopen]: failed to open stream: No such file or directory Quote:
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
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|