hammerklavier Posted December 23, 2008 Share Posted December 23, 2008 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted December 23, 2008 Share Posted December 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
hammerklavier Posted December 23, 2008 Author Share Posted December 23, 2008 I haven't declared it....... I thought that reading it in blank would make it change the name of the file to it ........... is it wrong ?? Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted December 23, 2008 Share Posted December 23, 2008 Well, since you haven't declared $poster_name, it's considered null, resulting in a non-existent filename Quote Link to comment Share on other sites More sharing options...
hammerklavier Posted December 24, 2008 Author Share Posted December 24, 2008 and what should I declare it ?? Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted December 24, 2008 Share Posted December 24, 2008 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']; ?> Quote Link to comment Share on other sites More sharing options...
hammerklavier Posted December 24, 2008 Author Share Posted December 24, 2008 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
hammerklavier Posted December 24, 2008 Author Share Posted December 24, 2008 <? // 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
hammerklavier Posted December 24, 2008 Author Share Posted December 24, 2008 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
hammerklavier Posted December 24, 2008 Author Share Posted December 24, 2008 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 !"); // }*/ Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted December 24, 2008 Share Posted December 24, 2008 Alright, well what error(s) is this script returning? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.