0

i am trying to transfer file from user to my server and than upload the file , the issue is when i know the file name(hard code) the file is being uploaded perfectly fine .and the file is transferred to my folder but the issue is i cannot get the file name in my fopen function.i have tried storing it in a varaible and try fopen($a.csv,"r") or fopen(($_FILES["file"]["name"].csv", "r")) but get the error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\pm\upload.php on line... HEERE IS MY CODE can some one fix my problem ?

if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  $a=$_FILES["file"]["name"];}
}
$con =  mysql_connect("localhost","root","");
if (!$con)
{
 die('Could not connect: ' . mysql_error());
}mysql_select_db("pm", $con);
$dum=false;
if (($handle = fopen($_FILES["file"]["name"].csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {

. .. ... ....

the error is on the line if (($handle = fopen($_FILES["file"]["name"].csv", "r")) !== FALSE) { have tried to upload without extension of the file ! kindly help

1
  • It should work right away without the file extension! Commented Aug 13, 2011 at 17:07

1 Answer 1

1

Try:

if (($handle = fopen('upload/'.$_FILES['file']['name'], 'r')) !== FALSE) {

You moved the file to the upload directory, that's where you should read it from.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.