0

hi guys.. how are you all??
ok, i need you help to make this happen...


i want to create a system that allow people to upload big files and you all know that php time limit is 5 minutes and size limit is 5 mb max.. in case we increased the size limit, the time limit will affect us right??

so how can i create a system that upload more than 5 mb and ignore the time limit??


this is a normal uploading script that i made for the system but it doesnt really do required job... how can i improve it to be able to upload more in more than 5 minutes...

<?php
$uploaddir = '/uploads/images/all/'; 
$ref = $_SERVER['HTTP_REFERER'];
if(!isset($_COOKIE['elb'])){ header("location: $ref");} else{
$elb = $_COOKIE['elb'];
include "engine/db/main.php";
$db = new db();
$db->connect();
$db->select("pics"); // my own db class
$elb = mysql_real_escape_string($_COOKIE['elb']);
$uid = mysql_real_escape_string($_COOKIE['ln']);
$q = mysql_query("SELECT * FROM elb WHERE md5id='$elb' AND uid = '$uid'")or die("there is no such elb");
if(mysql_num_rows($q) == 0){
$time = date()+60*60;
setcookie("error", "Not Valid Elbum. please try again", $time);
header("location: 404.php");
}
// now lets start doing the real job of uploading
$ran = rand();
$file = $uploaddir . $ran . basename($_FILES['uploadfile']['name']); 
$size=$_FILES['uploadfile']['size'];
if($size>5120000)
{
	echo "error file size > 500 MB";
	unlink($_FILES['uploadfile']['tmp_name']);
	exit;
}
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success"; 
  // ignore this part, it is for resizing images
  include("classes/resize-class.php");
	// *** 1) Initialise / load images
	$resizeObj = new resize($file);
	$resizeObj2 = new resize($file);
	$resizeObj3 = new resize($file);
	$resizeObj4 = new resize($file);
	// *** 2) Resize images (options: exact, portrait, landscape, auto, crop)
	$resizeObj -> resizeImage(65, 65, 'exact');
	$resizeObj2 -> resizeImage(500, 500, 'exact');
	$resizeObj3 -> resizeImage(1000, 700, 'exact');
	$resizeObj4 -> resizeImage(200, 200, 'exact');
$md5pic = md5($file);
	// *** 3) Save images
	$resizeObj -> saveImage('uploads/images/small/'.$file, 100);
    $resizeObj2 -> saveImage('uploads/images/medium/'.$file, 100);
	$resizeObj3 -> saveImage('uploads/images/big/'.$file, 100);
	$resizeObj4 -> saveImage('uploads/images/profile/'.$file, 100);
	$md5 = md5($pic);
	$q = mysql_query("INSERT INTO `all`(id, owner, name, des, md5, gallery) VALUES ('', '$uid', '$file', '$des', '$md5', '$elb'");
  
  
  
} else {
	echo "error ".$_FILES['uploadfile']['error']." -|-|- ".$_FILES['uploadfile']['tmp_name']." %-%-% ".$file."($size)";
}
?>

any help will be highly appreciated !!!!

3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by G&G Designing
0

hi guys.. how are you all??
ok, i need you help to make this happen...


i want to create a system that allow people to upload big files and you all know that php time limit is 5 minutes and size limit is 5 mb max.. in case we increased the size limit, the time limit will affect us right??

so how can i create a system that upload more than 5 mb and ignore the time limit??


this is a normal uploading script that i made for the system but it doesnt really do required job... how can i improve it to be able to upload more in more than 5 minutes...

<?php
$uploaddir = '/uploads/images/all/'; 
$ref = $_SERVER['HTTP_REFERER'];
if(!isset($_COOKIE['elb'])){ header("location: $ref");} else{
$elb = $_COOKIE['elb'];
include "engine/db/main.php";
$db = new db();
$db->connect();
$db->select("pics"); // my own db class
$elb = mysql_real_escape_string($_COOKIE['elb']);
$uid = mysql_real_escape_string($_COOKIE['ln']);
$q = mysql_query("SELECT * FROM elb WHERE md5id='$elb' AND uid = '$uid'")or die("there is no such elb");
if(mysql_num_rows($q) == 0){
$time = date()+60*60;
setcookie("error", "Not Valid Elbum. please try again", $time);
header("location: 404.php");
}
// now lets start doing the real job of uploading
$ran = rand();
$file = $uploaddir . $ran . basename($_FILES['uploadfile']['name']); 
$size=$_FILES['uploadfile']['size'];
if($size>5120000)
{
	echo "error file size > 500 MB";
	unlink($_FILES['uploadfile']['tmp_name']);
	exit;
}
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success"; 
  // ignore this part, it is for resizing images
  include("classes/resize-class.php");
	// *** 1) Initialise / load images
	$resizeObj = new resize($file);
	$resizeObj2 = new resize($file);
	$resizeObj3 = new resize($file);
	$resizeObj4 = new resize($file);
	// *** 2) Resize images (options: exact, portrait, landscape, auto, crop)
	$resizeObj -> resizeImage(65, 65, 'exact');
	$resizeObj2 -> resizeImage(500, 500, 'exact');
	$resizeObj3 -> resizeImage(1000, 700, 'exact');
	$resizeObj4 -> resizeImage(200, 200, 'exact');
$md5pic = md5($file);
	// *** 3) Save images
	$resizeObj -> saveImage('uploads/images/small/'.$file, 100);
    $resizeObj2 -> saveImage('uploads/images/medium/'.$file, 100);
	$resizeObj3 -> saveImage('uploads/images/big/'.$file, 100);
	$resizeObj4 -> saveImage('uploads/images/profile/'.$file, 100);
	$md5 = md5($pic);
	$q = mysql_query("INSERT INTO `all`(id, owner, name, des, md5, gallery) VALUES ('', '$uid', '$file', '$des', '$md5', '$elb'");
  
  
  
} else {
	echo "error ".$_FILES['uploadfile']['error']." -|-|- ".$_FILES['uploadfile']['tmp_name']." %-%-% ".$file."($size)";
}
?>

any help will be highly appreciated !!!!

I've never had a problem with the 5mb limitation using a normal html form + php upload, but then again, I have always hosted webpages on my own server, with WAMP. Probably less restrictions.

You should be able to change the default values through changing some values in your php.ini file.
Open it and change upload_max_filesize = 2M to upload_max_filesize = 500M.
You can also try changing the post_max_size value.
After altering those values remember to restart apache and php services

To give the script unlimited time to execute, try adding set_time_limit(0); in the php script.

If you can't access the php.ini on the server try adding
ini_set('post_max_size', '500M');
ini_set('upload_max_filesize', '500M');
to your php script. I'm not sure if this will work though.

On last way I can think of if you can't access php.ini is to create your own php.ini or .htaccess file with only the necessary values and upload it to your root directory on your server via ftp.

php.ini

upload_max_filesize = 500M
post_max_size = 500M

or
.htaccess

php_value upload_max_filesize 500M
php_value post_max_size 500M

One of those might work, but don't use both simultaneously.

This should set you onto the right track. There are lots of solutions if google the problem.

0

^ He has it correct, but if your not on a dedicated hosting environment, for example if your on a shared hosting environment, forget it.. the hoster won't let you change the php.ini file, and even if they do.. they will restrict your file upload amount down again. it's set to 500mb for a reason...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.