Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zip will cannot be read from sql db

Status
Not open for further replies.

bobrivers2003

Technical User
Oct 28, 2005
96
GB
I have a html form that allows files to be uploaded to a mysql server, max file size 2mb. I have a page that lists all the files as links and when clicked allows the files to be saved or opened.

It works a treat with all types of files and validates if over 2 mb.

However if I try to upload a zip file and then attempt to open it the archive is not recognised.

This is the form:

<td width=\"246\">Attachment- 2Mb Limit: (Click Browse) <br><input type=\"hidden\" name=\"MAXFILESIZE\" value=\"2000000\"><input name=\"userfile\" type=\"file\" class=\"box\" id=\"userfile\">


This is the php that stores it to the db:


$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

if(!($fileName==null))
{

$fp = fopen($tmpName, 'r');
$content = fread($fp, $fileSize);
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}



$query = "INSERT INTO table (username, date, time, query, p_level, a_name, state, feedback, filename, size, type, content ) VALUES('$cookieuname', '$currdate', '$currtime', '$query', '0', '$assignedTo', '$stateVar', '$feedbackVar', '$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('<b>Error, query failed</b>');


Can anyone tell me why zip files won't work?
 
you're not doing yourself any favours with debugging the query. change the query line to:

Code:
mysql_query($query) or die ("Error: " .mysql_error());

you should also put the addslashes on $content within the gpc test. change to

Code:
            fclose($fp); 
             
            if(!get_magic_quotes_gpc()) 
            { 
                $content = addslashes($content);
                $fileName = addslashes($fileName); 
            }

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top