ddicicco Posted October 22, 2007 Share Posted October 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74262-pdf-upload-to-mysql-not-a-valid-stream-resource/ Share on other sites More sharing options...
MadTechie Posted October 22, 2007 Share Posted October 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74262-pdf-upload-to-mysql-not-a-valid-stream-resource/#findComment-375195 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.