Forum Moderators: coopster

Message Too Old, No Replies

PHP Upload large files

         

ayushchd

10:18 am on Oct 19, 2009 (gmt 0)

10+ Year Member



Hey,

I want to upload ZIP Files upto 3M.
The max_upload_filesize on my server is set to 2M.
When I upload small files, it works but whenever there are large files it takes lots of time and the same page reloads.

Is it a timeout problem or what? What happens when a file greater than the size allowed is encountered?
What is happening is if I upload a file greater than 3M, it takes some time and loads the same page.
Please see the following and suggest..


ini_set('upload_max_filesize', '3M');
set_time_limit(600);
define('PG_REQUIRE_MEMBER_LOGIN', true);

require_once 'inc/init.php';

if (isset($_POST['btn'])) {
$file_name = $_FILES['uploaded']['name']; // Get File Name
$file_ext = strtolower(end(explode(".",$file_name))); // File Extension
$legal = array("zip","rar");
if (!in_array($file_ext, $legal))
{
$mss = $Message->DrawBox("Invalid File Type", "error");
} else if ($_FILES["uploaded"]["size"] > 3145728) {
$mss = $Message->DrawBox("File Limit Exceeded", "error");
} else {

$_FILES['uploaded']['name'] = $_SESSION['warp_username'].".$file_ext";

$target_path = BASE_FOLDER . "di_submission/";

$target_path = $target_path . basename( $_FILES['uploaded']['name']);

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) {
chmod($target_path, 0644);
$sql = "UPDATE warp_schools SET di='". $_FILES['uploaded']['name']. "' where id=$_SESSION[warp_user_id];";
mysql_query($sql);
$mss = $Message->DrawBox("Your entry has been accepted", "success");
}
}
}

kamperzoid

10:40 am on Oct 19, 2009 (gmt 0)

10+ Year Member



There is one more option you have to set and that's "post_max_size". This has to be big enough.

greetz

ayushchd

11:24 am on Oct 19, 2009 (gmt 0)

10+ Year Member



even that didn't work..
is it not possible to increase the limit using ini_set()?

rocknbil

5:05 pm on Oct 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can increase the max_post_size, max upload, etc. via the php.ini or, safer, create an .htaccess file on a per-directory basis with

php_flag file_uploads on
php_value post_max_size "20M"
php_value upload_max_filesize "10M"
php_value max_input_time "300"
php_value memory_limit "64M"

This can all be verified by pulling a phpinfo() after adding the .htaccess file.

(Off-topic, for IMAGES)
PHP has a 32MB memory limit and 2 MB upload limit for a reason. The GD toolkit manages images by creating an uncompressed bitmap in memory. When you step outside a maximum 2MB upload, you have to increase PHP memory usage waaaay up to avoid fatal errors and if you're on shared hosting, they won't like this one bit. Besides, it's just an inefficient way to manage images.

The solution lies in the installation of ImageMagick binaries and the Imagick PHP interface. This spawns an external process allowing ImageMagick to do the image manipulation and uses a fraction of the memory. In the above example, you could probably leave the PHP memory limit at default (32MB.)

ayushchd

7:56 am on Oct 20, 2009 (gmt 0)

10+ Year Member



Neither ini_set() nor .htaccess worked..I guess I need to contact the server admin himself.