Forum Moderators: coopster

Message Too Old, No Replies

Files not Uploading to PHP Mysql

Files over 1mg not uploading

         

m4tt

11:17 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



Hi I am attempting to upload files over 1mg and am getting the following:

Warning: fread(): supplied argument is not a valid stream resource in /home/symmetry/public_html/sitemanage/document/index.php on line 25

Warning: fclose(): supplied argument is not a valid stream resource in /home/symmetry/public_html/sitemanage/document/index.php on line 27

Here is the code:

<?
include '../library/config.php';
include '../library/opendb.php';

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

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

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


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

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

echo "<h5>File $fileName uploaded</h5>";
}
?>
<h4>Add Document</h4>

<div id="cform">

<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<input type="hidden" name="MAX_FILE_SIZE" value="200000000000000"><input name="userfile" type="file" class="box" id="userfile">
<input name="upload" type="submit" class="box" id="upload" value=" Upload ">
</form>
</div>

Anyone have any ideas on where I am giong wrong?

jatar_k

11:24 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if it is specifically files over 1MB maybe take a read through
[php.net...]

and more specifically
[php.net...]

m4tt

11:29 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



I have checked the max_filesize and limits and they are large enough. Could it be the time limit? Have you come across this yourself?

m4tt

11:34 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



I also tried a file with no spaces.. and still got this:

Warning: fread(): supplied argument is not a valid stream resource in /home/symmetry/public_html/sitemanage/document/index.php on line 25

Warning: fclose(): supplied argument is not a valid stream resource in /home/symmetry/public_html/sitemanage/document/index.php on line 27

jezra

12:33 am on Mar 9, 2006 (gmt 0)

10+ Year Member



If you have checked that the file size is within the limits for both the upload size as well as the max post size, then you should look at script execution time, not just in the php.ini file but also as part of your server software. I had a similar problem that took me a few days to track down in the IIS control panel. I'm going to assume that Apache has as similar setting for max script execution time.

m4tt

12:38 am on Mar 9, 2006 (gmt 0)

10+ Year Member



It is set to 30 seconds when I do phpinfo...This would definately be it?

jatar_k

12:54 am on Mar 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



could very well be, I have had issues with uploads timing out before

m4tt

12:54 am on Mar 9, 2006 (gmt 0)

10+ Year Member



Changed the setting to 60 seconds and I still get the following:

Anyone have any ideas at all?

Warning: fread(): supplied argument is not a valid stream resource in /home/symmetry/public_html/sitemanage/document/index.php on line 25

Warning: fclose(): supplied argument is not a valid stream resource in /home/symmetry/public_html/sitemanage/document/index.php on line 27

m4tt

11:34 am on Mar 9, 2006 (gmt 0)

10+ Year Member



Still having no luck with this. Can anyone assist?

m4tt

1:15 pm on Mar 9, 2006 (gmt 0)

10+ Year Member



Here is the problem:

[dev.mysql.com...]

mySql packet size...

henry0

1:22 pm on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, glad you found it
learning from your experience.

m4tt

1:30 pm on Mar 9, 2006 (gmt 0)

10+ Year Member



Yep, learnt my lesson...