View Single Post
Old 08-26-2004, 04:27 AM   #5 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Hi,

I made a script to accomplish the following it works with Apache under windows however on my production server running Apache in Linux it had some errors

I am running php-4.3.8-1, Apache 2.0.50-1 and Mysql-4.8.20-1

My db structure:
mysql> CREATE TABLE image (
> id_files tinyint(3) unsigned NOT NULL auto_increment,
> bin_data longblob NOT NULL,
> description tinytext NOT NULL,
> filename varchar(50) NOT NULL,
> filesize varchar(50) NOT NULL,
> filetype varchar(50) NOT NULL,
> PRIMARY KEY (id_files)
> );


Here's the code:

Code:
<?php
if ($action == "upload") {
  // upload data and insert it into the db now
  include "open_db.inc";

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

} else {
?>
<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
}
?>
Running this script gives an error as follows:


Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/httpd/htdocs/works/add.php on line 14
Thank you. The new file was successfully added to our database.


I can view the file being uploaded though. But the error confuses me.

How can I eliminate it? Any help will be greatly valued.

Thanks

Last edited by infinite_root; 08-26-2004 at 04:54 AM.
infinite_root is offline   Reply With Quote