Page 1 of 1

Uploading, Saving and Downloading Binary Data in a MySQL Dat

Posted: Sun Oct 12, 2003 2:12 pm
by bobby
Ok once again another tutorial that i can't get to work. dunno about you guys but almost every tutorial i do these seems to be a problem and i can't get it to work.....lol

Here's the latest, anyone done this one at onlamp.com

I'm supposed to be able to upload a binary file to a database. However, when i check my database no binary file is uploaded, plus i dont get to see main.php....... i have no idea why


anybody else got a clue

Code: Select all

<?php
if ($action == "upload") &#123;
  // ok, let's get the uploaded data and insert it into the db now
  
  include("C:\Program Files\Apache Group\Apache2\htdocs\open_db.inc");

  if (isset($binFile) && $binFile != "none") &#123;
    $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
    $strDescription = addslashes(nl2br($txtDescription));
    $sql = "INSERT INTO tbl_Files ";
    $sql .= "(bin_data , description  , filename, filesize, filetype) ";
    $sql .= "VALUES ('$strDescription', '$data', ";
    $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
    $result = mysql_query($sql, $db);
   
    mysql_free_result($result); // it's always nice to clean up!
    echo "Thank you. The new file was successfully added to our database.<br><br>";
    echo "<a href='main.php'>Continue</a>";
  &#125;
  mysql_close();

&#125; else &#123;
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
 <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
 <INPUT TYPE="hidden" NAME="action" VALUE="upload">
 <TABLE BORDER="1">
  <TR>
   <TD>Description: </TD>
   <TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
  </TR>
  <TR>
   <TD>File: </TD>
   <TD><INPUT TYPE="file" NAME="binFile"></TD>
  </TR>
  <TR>
   <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
  </TR>
 </TABLE>
</FORM>
</BODY>
</HTML>
<?php
&#125;
?>

Posted: Sun Oct 12, 2003 5:11 pm
by JAM

Code: Select all

if ($action == "upload") {
If you have register_globals = off in your php.ini, the above should be:

Code: Select all

if ($_POST['action'] == "upload") {
Concerning Passing Variables in PHP 4.2+

Edit: Thanks ;)

Posted: Sun Oct 12, 2003 5:16 pm
by m3mn0n
ogg = off

;)

Posted: Sun Oct 12, 2003 6:47 pm
by Stoneguard
ogg = off
good old Nanny Ogg, she always was a bit off, but one heck of a witch!

Posted: Mon Oct 13, 2003 5:19 pm
by bobby
Hi guys thanks for the tip

i think i have got further tan before with your help. But it now says

error number 1054 unkonw column id_files in where clause

I tried putting the id_files coloumn in the query but that didnt work

any one else

Posted: Mon Oct 13, 2003 5:52 pm
by JAM
It's not from this piece of script. You have no where-clause in the original post, so we can't help you spot the problem.

Posted: Wed Oct 15, 2003 3:59 am
by bobby
Hi Guys,

Not to sure what u mean when u say

'It's not from this piece of script'. Id_files is a colunm in the table that the tutorial asked me to create. i know theres isnt reference to it in the first post. I thought maybe thats why it wasn't working. The code has been copied froma tutorial at onlamp website. I realise that code often found on the web is buggy so i thought i would try and add the id_files bit to see if it works.

Also im aware that there isnt a where clause, however i thought that the above code showed another way of doing the same as the where clause.

I am newbie, still trying to pick it up

thanks