Hi!

I have a problem with .pdf upload size...

In input form i have set it like so:

<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">

in php.ini

; Maximum allowed size for uploaded files.
upload_max_filesize = 150M

but i can not upload the file of 1MB...

I have looked at my error log and this is what i get

PHP Fatal error: Allowed memory size of 33554432 bytes exhausted

i have increased the memory limit to

memory_limit = 256M

and now when i look at my php error log it is empty (!?) but i stil cant upload 1MB .pdf file...

script only sends echo that the upload failed...

Help!?

Your host may have restricted this. :) Try contacting them

Hi,

You need to run this simple script on your server

    <?php 
    phpinfo(); 
    ?>

First, look for the value of **Server API ** is it Apache module or apache handler?
Yes? You need to add this on your .htaccess file or create one if you don't have it.

    php_value upload_max_filesize 100M
    php_value post_max_size 100M
    php_value max_execution_time 1000
    php_value max_input_time 1000

No? What is it? Is it CGI or Fast CGI? If yes, create a new text document (preferrably on notepad) save it as php.ini file add codes below

    post_max_size 100M
    upload_max_filesize 100M
    max_execution_time 1000

Set your FTP program transfer mode to auto, and then upload the newly created php.ini file to the root directory of your site. Test your upload script.

Else? Contact your hosting support, and ask them to increase your upload limit and execution time for php script.

Hi,

thank you for your reply.

I am running it on localhost (MAMP). I have checked all values and everything is setup corectly... (well i think it is but since it is not working it isnt hahaha) Atleast in php.ini and even in php.ini.temp i changed all the values.

Server API is Apache 2.0 Handler.

In database i tried to use LONGBLOB and MEDIUMBLOB with no success...

I dont think it is the script since im uploading smaller files without any problems but here is the code

<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$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($tmpName));
$content = addslashes($content);
fclose($fp);

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

$con = mysql_connect("*","*","*");
if (!$con)
  {
  die('Could not connect to the database: ' . mysql_error());
  }

mysql_select_db("*", $con);

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

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

echo "<br>File $fileName uploaded<br>";
}

mysql_close($con);
?>

and this is the part from the form

Attach File:<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
<input name="userfile" type="file" id="userfile">
<input name="upload" type="submit" class="box" id="upload" value=" Upload ">

Hi,

Can you try changing this part of your code,

 $fp = fopen($tmpName, 'r');

to

    $fp = fopen($tmpName, 'rb');

I suspect the time out is due to excessive memory usage which is caused by the fopen function trying to read a pdf file format as text rather than read as binary.. However, 'r' alone works on images to blob, so I am suggesting untested approach here just to give you a heads up :).

changed it, but thats not it...

If it is a pdf doc, why save it to your database (maybe I'm missing something.. :) )?

I've downloaded in excess of 200 mb pdf docs to my server and let users download with no hassles at all with the following... (maybe still loosing the plot here, if so, sorry, ignore my post.)

I have a php script called say "yourpdfdownloadnamehere.php". Within, the following -

<?php
header('Content-disposition: attachment; filename=mynamedpdfhere.pdf');
header('Content-type:  application/pdf');
readfile('mynamedhere.pdf');
?>

In my form with say an image to the pdf -

<a href="yourpdfdownloadnamehere.php" style="text-decoration:none; color:#FFF"><strong style="color:#FFF">Download My PDF eBrochure    </strong><img src="images/pdf_icon.png" title="Click To Download my PDF eBrochure" width="30" height="30" alt="Download PDF"/></a>

Ahh, sorry my bad, upload, not download...

Server restrictions on max size as per .ini settings, time out restrictions.

First off did you set the content as a blob in mysql. Second, go into your http conf file and just like what veedeoo said, change the values to something like that. Third, no need to have a hidden field for the upload size, just have the file upload and a submit button. Fourth, your $query statement needs to change to

mysql_query("INSERT INTO Persons (name, size, type, content)
VALUES ('$fileName', '$fileSize', '$fileType', '$content')");
or
$query = "INSERT INTO Persons (name, size, type, content)
VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

Hope this helps.

Hi! Thank you all for your time and effort.

There is no problem with the script since it uploads everything smaller than 500k. I tried to upload it to online server and it works with files up to 2MB so i hope that will solve the problem since i will use that server in the future. But it is reeall pain in the ass that i cant do it on my localhost and it is driving me crazy! :) I want to solve that problem... So if you could suggest something... Like i said, i changed all values in php.ini and php.ini.temp but it didnt help. in my httpd.conf i dont have values that restrict or allow upload size and it seams i dont have .htaccess file to add those values that veedeoo said i should... Where should i create .htaccess? In my script folder or in apache folder?

Thanks!

The first and only things to check (or ask your host provider to check) are the values of upload_max_filesize (Default 2M) memory_limit (Default 16M) and post_max_size (Default 8M) in the php.ini. Increase all as per your need.

Remember to restart your web server (localhost) and you should see the changed file sizes.

Thank you. It didnt solved the problem on my localhost but atleast i know that my script is working fine and it is server issue. I will contact my hosting provider to see about increasing memory limit.

I know this thread has been marked solved, but I think it is worth mentioning that I was able to recreate your problem.. For PDF to blob, PDF should be at least below 5MB and 10MB is the maximum threshold in MYsql (InnoDB storage engine.. again I believe this is server setting dependent, but in local server it is just too difficult to predect or observe the actual minimum and maximum), OR ELSE you will get the "mysql have gone away error"..

In the upload problem, it is not really happening after you set up your maximum upload file size, the problem seems to be on the fread.. retrieving the pdf file from the PHP temp directory.. this is where the process tend to fail.

I was able to do comparison between the fread and file_get_contents to handle the uploaded PDF file just for the purpose on converting it to BLOB data. However, the processing problems remains the same.. script timed out everytime the PDF file size exceeded the 10MB threshold.

My suggestion is to ONLY allow PDF file size of less than 2MB if this script is going to be running on the production server. Server resources must always be put into consideration at all times.

Hi! Thank you for your effort to solve this issue. The thing is, i am working on a application for parts stock management where with part description comes part certificate. The people that are working there are reeally old :) so there is no way they will want to make pdf smaller because they are not so good with clicking stuff not to mention anything else hahahaha but there wont be manny users and dont think there will be more than one user at the time + once everything is inserted in the data records new records wont be added so often. Based on that i can give them a bit bigger upload size.

Second thing... The issue i had on local host is resolved... How? When i was writing this post, i have used Mac OSX + MAMP PRO where i had problems changing the upload restrictions. I have moved it to Windows + WAMP, corrected php.ini values and as everybody said, it worked without any problems. I dont know what could be the problem... Also tried with XAMPP on Mac but also with no success... I just reacently got a Mac as a gift but no offence to anybody, it is really crapy if you want to use it for something else than personal use (go to facebook and watch the pictures hahaha).

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.