Jump to content

PDF Upload to MYSQL: not a valid stream resource


ddicicco

Recommended Posts

I am writing a law firm client management system.  Part of my program allows me to upload a file to my website and to associate that file with a client so that the client can access the file over the web.

 

I have successfully been able to upload .doc files, .gif files, and other file types using the script that I will post below.  I have been successful in uploading files such as gif images and other small files.  When I try to upload larger files, specifically a 4 mb pdf file, I get the following error:

 

Warning: fread(): supplied argument is not a valid stream resource in /home/ddicicco/public_html/LMS/uploadtest.php on line 26

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/ddicicco/public_html/LMS/uploadtest.php on line 28

 

Here is the skinny version of my code:

<html>
<head>
<title>Upload File To MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>

<body>
<?
if(isset($_POST['upload']))
{
	$fileName = $_FILES['userfile']['name'];
	$tmpName  = $_FILES['userfile']['tmp_name'];
	$fileSize = $_FILES['userfile']['size'];
	$fileType = $_FILES['userfile']['type'];

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

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



	$query = "INSERT INTO upload (name, size, type, content ) ".
	         "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

	mysql_query($query) or die('Error, query failed');					

	echo "<br>File $fileName uploaded<br>";
}		
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
  <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr> 
      <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="200000000"><input name="userfile" type="file" class="box" id="userfile">
	 </td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value="  Upload  "></td>
    </tr>
  </table>
</form>
</body>
</html>

My "uploads" table, content field is a mediumblob.  Please help!  This is driving me nuts.

Link to comment
Share on other sites

the file isn't uploading..

check your timeouts,

The MAX_FILE_SIZE item cannot specify a file size greater than the file size that has been set in the upload_max_filesize ini-setting. The default is 2 Megabytes.

 

Note:  max_execution_time only affects the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, time taken by the file upload process, etc. is not included when determining the maximum time that the script has been running.

 

max_input_time sets the maximum time, in seconds, the script is allowed to receive input; this includes file uploads. For large or multiple files, or users on slower connections, the default of 60 seconds may be exceeded.

 

If post_max_size is set too small, large files cannot be uploaded. Make sure you set post_max_size large enough.

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.