Jump to content

file upload problems


hammerklavier

Recommended Posts

well I give up....... been all day trying to make this work out......... it's a simple upload function............. when I upload the file it goes runs the DIE function......... no idea why..... I've tried everything ......thanks in advance.....

 

oh when I run the is_uploaded function it executes the else "echo "All is ok so far ......<br><br>";......... so at that point it seems everything is fine.......

 

even ran a bunch of echoes to see if there was a problem...... folder is 777 btw.....

 

thanks in advance

 

 

 

 

<?

 

//phpinfo();

 

echo getcwd();

 

 

if (!$question || !$answer)

{

echo "Fill all fields";

echo "<a href='creategallery.php'>Go back</a>";

}

 

  $db = @mysql_pconnect("localhost", "login", "password");

  if (!$db)

  {

  echo "Error";

  exit;

  }

 

if (mysql_select_db("database_com"))

{

  echo "<font face=Arial, Helvetica, sans-serif size=2>Connection successful </font><br><br>";

}

 

 

$sql = "insert into test_questions (question, answer, imagefile) values ('$question', '$answer', '$filename')";

 

$estado = mysql_query($sql, $db);

 

$qry = mysql_fetch_array($estado);

 

if (!$estado)

{

print "Problem while executing .......<PRE>$sql</PRE>";

print mysql_error();

exit;

}

 

echo "<br><br>".$filename;

echo "<br><br>".$question."<br><br>";

 

if (!is_uploaded_file($filename))

{

echo "Problem uploading the file";

} else {

echo "All is ok so far ......<br><br>";

}

 

 

if ($poster_name != "")

{   

move_uploaded_file("$filename", "/store/home/site/html/qa/$poster_name") or die("Couldn't Upload Your File.");

       

} else {

 

die("YOU HAVEN'T UPLOADED ANYTHING!");

}

 

if (!$total)

{

$total = mysql_insert_id();

     

         

$sql = "update test_questions set imagefile = '$poster_name' where id = $total";

$result = mysql_query($sql,$conn);

 

 

echo $qry[question];         

echo "<center><font face='arial' size='2'><b>Cool addition man !</b></font></center><br><br><br>";

echo "<center><font face='arial' size='2'><b><a href='add.html'>Add another question</a></b></font></center><br>";

 

}

 

 

?>

Link to comment
Share on other sites

Where do you declare the $poster_name variable?

 

A few tips:

- Suppressing errors with the @ symbol is discouraged as it slows the script, and it doesn't give any error at all.

 

- Make sure to put quotes around your array keys, this also slows the script down as it searches for a constant first.

<?php
echo $qry['question'];
//Instead of
echo $qry[question];  
?>

 

Also, it's faster to use single-quotes as opposed to double-quotes when the string has no variable.

Link to comment
Share on other sites

You should definitely initialize it at the beginning of the script (for security reasons)

 

Example

<?php
$poster_name = false;
?>

 

You could declare it as the filename supplied by the person who is uploading it.

 

Example

<?php
$poster_name = $_FILES['inputName']['name'];
?>

 

Where 'inputName' is the name you gave to your input field (the one where you select your file for uploading).

 

You don't have to use the exact filename as supplied by the uploader, either. You could prefix a timestamp onto it (to lessen the chance of having filenames overlap):

 

Example

<?php
$poster_name = time().$_FILES['inputName']['name'];
?>

Link to comment
Share on other sites

 

 

this is the script now...........still is not working :(

 

<? 

 

//phpinfo();

 

echo getcwd();

 

 

if (!$question || !$answer)

  {

      echo "Fill all fields";

      echo "<a href='creategallery.php'>Go back</a>";

  }

 

  $db = @mysql_pconnect("localhost", "login", "password");

  if (!$db)

  {

      echo "Error";

      exit;

  }

 

  if (mysql_select_db("database_com"))

  {

        echo "<font face=Arial, Helvetica, sans-serif size=2>Connection successful </font><br><br>";

  }     

 

 

  $sql = "insert into test_questions (question, answer, imagefile) values ('$question', '$answer', '$filename')";

 

  $estado = mysql_query($sql, $db);

 

  $qry = mysql_fetch_array($estado);

 

  if (!$estado)

  {

      print "Problem while executing .......<PRE>$sql</PRE>";

      print mysql_error();

      exit;

  }

 

  echo "<br><br>".$filename;

  echo "<br><br>".$question."<br><br>"; 

 

  if (!is_uploaded_file($filename))

  {

      echo "Problem uploading the file";

  } else {

      echo "All is ok so far ......<br><br>";

  }

     

 

// included declaring poster_name

 

$poster_name = false;

 

 

  if ($poster_name != "")

  { 

      move_uploaded_file("$filename", "/store/home/site/html/qa/$poster_name") or die("Couldn't Upload Your File.");

     

  } else {

 

      die("YOU HAVEN'T UPLOADED ANYTHING!");

  }

 

  if (!$total)

  {

      $total = mysql_insert_id();

     

         

      $sql = "update test_questions set imagefile = '$poster_name' where id = $total";

      $result = mysql_query($sql,$conn);

 

 

      echo $qry[question];         

      echo "<center><font face='arial' size='2'><b>Cool addition man !</b></font></center><br><br><br>";

      echo "<center><font face='arial' size='2'><b><a href='add.html'>Add another question</a></b></font></center><br>";

 

  }

 

 

?>

 

Link to comment
Share on other sites


<?   

// included declaring poster_name

$poster_name = false;


//phpinfo();

echo getcwd();


if (!$question || !$answer)
   {
      echo "Fill all fields";
      echo "<a href='creategallery.php'>Go back</a>";
   }
   
   $db = mysql_pconnect("localhost", "login", "password");
   if (!$db)
   {
      echo "Error";
      exit;
   }

   if (mysql_select_db("database_com"))
   {
         echo "<font face=Arial, Helvetica, sans-serif size=2>Connection successful </font><br><br>";
   }     
   

   $sql = "insert into test_questions (question, answer, imagefile) values ('$question', '$answer', '$filename')";

   $estado = mysql_query($sql, $db);

   $qry = mysql_fetch_array($estado);

   if (!$estado)
   {
      print "Problem while executing .......<PRE>$sql</PRE>";
      print mysql_error();
      exit;
   }
   
   echo "<br><br>".$filename;
   echo "<br><br>".$question."<br><br>";   
   
   if (!is_uploaded_file($filename))
   {
      echo "Problem uploading the file";
   } else {
      echo "All is ok so far ......<br><br>";
   }
     


   if ($poster_name != "")
   {   
      move_uploaded_file("$filename", "/store/home/site/html/qa/$poster_name") or die("Couldn't Upload Your File.");
       
   } else {

      die("YOU HAVEN'T UPLOADED ANYTHING!");
   }

   if (!$total)
   {
      $total = mysql_insert_id();
       
           
      $sql = "update test_questions set imagefile = '$poster_name' where id = $total";
      $result = mysql_query($sql,$conn);
   
   
      echo $qry['question'];           
      echo "<center><font face='arial' size='2'><b>Cool addition man !</b></font></center><br><br><br>";
      echo "<center><font face='arial' size='2'><b><a href='add.html'>Add another question</a></b></font></center><br>";

   }


?>

Link to comment
Share on other sites

ok made a few changes in the script :

 

 

as you can see I fixed poster_name to read filename_name............ so here is my issue now.

 

if ($filename_name != "")

{   

move_uploaded_file("$filename", "/store/http/site/html/qa/$filename_name") or die("Couldn't Upload Your File.");

       

} else {

 

die("YOU HAVEN'T UPLOADED ANYTHING! !");

}

 

 

now before I got the YOU HAVENT UPLOADED ANYTHING die...................... now the Die I'm getting is the "couldnt upload your file"..........

 

any hints ? thanks in advance

 

 

<?

 

 

phpinfo();

 

echo getcwd();

 

 

 

 

if (!$question || !$answer)

{

      echo "Fill all fields";

      echo "<a href='creategallery.php'>Go back</a>";

}

 

  $db = @mysql_pconnect("localhost", "admin", "pass");

  if (!$db)

  {

  echo "Error";

  exit;

  }

 

if (mysql_select_db("database_com"))

{

  echo "<font face=Arial, Helvetica, sans-serif size=2>Connection successful  </font><br><br>";

}

 

 

$sql = "insert into test_questions (question, answer, imagefile) values ('$question', '$answer', '$filename')";

 

$estado = mysql_query($sql, $db);

 

$qry = mysql_fetch_array($estado);

 

if (!$estado)

{

print "Problem while executing ....... <PRE>$sql</PRE>";

print mysql_error();

exit;

}

 

echo "<br><br>".$filename;

echo "<br><br>".$question."<br><br>";

 

if (!is_uploaded_file($filename))

{

    echo "Problem uploading the file";

  } else {

      echo "All is ok so far ......<br><br>";

}

 

 

 

if ($filename_name != "")

{   

move_uploaded_file("$filename", "/store/http/site/html/qa/$filename_name") or die("Couldn't Upload Your File.");

       

} else {

 

die("YOU HAVEN'T UPLOADED ANYTHING! !");

}

 

if (!$total)

{

$total = mysql_insert_id();

     

         

$sql = "update test_questions set imagefile = '$filename_name' where id = $total";

$result = mysql_query($sql,$conn);

 

 

echo $qry[question];         

echo "<center><font face='arial' size='2'><b>Cool addition man !</b></font></center><br><br><br>";

echo "<center><font face='arial' size='2'><b><a href='add.html'>Add another question</a></b></font></center><br>";

 

}

 

 

?>

Link to comment
Share on other sites

ok I tried using copy and same error.................

 

so I'm guessing there is a problem moving the file ???

 

 

if (!copy($filename, "/home/site.com/site.com/html/qa/$filename_name"))

{

echo "Could not move file into directory";

}

 

 

 

//

// if ($filename_name != "")

// {   

// move_uploaded_file("$filename", "/store/home/site.com/site.com/html/qa/$filename_name") or die("Couldn't Upload Your File.");

//

// } else {

//

// die("No has subido archivo alguno !");

// }*/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.