...

View Full Version : uploading large files in php



mazazino
08-05-2007, 09:49 PM
hi, i used the normal move_uploaded_file() function to upload .rm music files and images using php..but now i need to upload large files..such as setups and installation programs..and for some reason, when i try uploading any other file using the same code, it gives me errors that dont make any sense..so is there a default maximum size set by the move_uploaded_file() function or is there another way of uploading larger files?

marek_mar
08-05-2007, 10:03 PM
There are a few settings that affect uploads. You should check post_max_size and max_input_time php.ini settings. I wouldn't recomment uploading really big files with the browser.

CFMaBiSmAd
08-05-2007, 10:12 PM
Since you mention setup and installation programs, I will assume you are not asking about a general visitor to your site, but are asking for your own use on your site?

Your hosting account control panel should have file functions that allow you to browse to a file on your local computer and move/copy/upload them to the server or you will need to FTP (File Transfer Protocol) them to the server, using an FTP client program (some browsers support this directly).

meth
08-05-2007, 11:48 PM
Large files are typically uploaded via php's ftp functions. Keep in mind that the vast majority of servers will not allow scripts to execute for the length of time required for large files despite runtime configuration.

http://www.php.net/ftp

JamieR
08-06-2007, 01:04 AM
Also pay notice to LimitRequestBody in Apache, I've had problems before where I've had php's max_input_size etc set correctly for uploading larger files, but would still have problems due to limitrequestbody being of a lower size.

http://httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody

mazazino
08-06-2007, 08:07 AM
Since you mention setup and installation programs, I will assume you are not asking about a general visitor to your site, but are asking for your own use on your site?

Your hosting account control panel should have file functions that allow you to browse to a file on your local computer and move/copy/upload them to the server or you will need to FTP (File Transfer Protocol) them to the server, using an FTP client program (some browsers support this directly).


ya im using it for my administrator's page so he can upload softwares to the main page..and I can do what u said about using FTP client program but the thing is all the softwares that will be uploaded are also loaded into the database..their directories, their sizes, names, and other information about the installation files..so if i upload each file on FTP program, i would have to manually update the DB daily to make an entry for the new software and this would be costly in time..so if there is another way to change the default maximum upload size in php, i need to know about it..

CFMaBiSmAd
08-06-2007, 08:20 AM
All the PHP settings that affect the maximum upload size are settable in php.ini or a .htaccess file.

mazazino
08-06-2007, 12:16 PM
ok so i used the following code to upload a setup file using ftp client, and it printed out the echo that says echo "Connected to $ftp_server, for user $ftp_user_name"; and then it also echoed Uploaded bluejsetup-205.exe to the ftp server as setupFile.exe"...but the thing is, i checked the directory of my website online, and setupFile.exe isnt there..i mean from what it looks like, it should work properly, but nothing happened in my directory online...anyone can help me with this?


$ftp_server = "/* my ftp server */";
$conn_id = ftp_connect($ftp_server);

// login with username and password
$ftp_user_name = "/* username */";
$ftp_user_pass = "/* password */";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}

// upload the file
$destination_file = "setupFile.exe";
$source_file = "bluejsetup-205.exe";

$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to the ftp server as $destination_file";
}

// close the FTP stream
ftp_close($conn_id);

mazazino
08-06-2007, 01:56 PM
ok it worked..i think the problem was that i didnt set it so it is visible to the outside..there was this function: $ch=ftp_site($conn_id,"chmod 777 ".$destination_file);
when i added it everything worked fine, but the thing now is that i copy and pasted the setup file in the same directory as the php file im working with..the variable u see below $local_file_name is set to a name of a file in my local directory that i put there myself just to try the ftp file transfer if it works and it worked..now the problem is i put the a <input type="file"> tag in the form that leads to this page, and the problem is i want the administrator to browse his computer to put any setup file he wants, and not have to copy paste the setup file and put it online manually before he can use the ftp file transfer to put the setup file in its appropriate directory..i dont know if you get what i mean but i mean i want the $local_file_name to have the complete path of the file the user will browse when using the <input type="file"> tag...can anyone help?


$ftp_server = "//my ftp server";
$conn_id = ftp_connect($ftp_server);

// login with username and password
$ftp_user_name = "// my username";
$ftp_user_pass = "// my pass";
$ftp_dir='/MYHOST.com/extras/softwares/'.$cat;

//$web_location is needed for the file_exists function, the directories used by FTP
//are not visible to it will will always return not found.
$web_dir='../../extras/softwares/'.$cat;
$local_file_name = "file.txt" //= $_FILES['directory']['name'];
$web_location=$web_dir.$local_file_name;

//build a fully qualified (FTP) path name where the file will reside
$destination_file=$ftp_dir.$local_file_name;

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $local_file_name, FTP_BINARY);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
//use ftp_site to change mode of the file
//this will allow it be visible by the world,
$ch=ftp_site($conn_id,"chmod 777 ".$destination_file);
// close the FTP stream
ftp_close($conn_id);
//verify file was written
if (file_exists($web_location))
{
echo "file was uploaded as $web_location";
}
else
{
echo "Could not create $web_location";
}
//end if

timgolding
08-06-2007, 02:31 PM
Is this the line to set max file size?



; Maximum size of POST data that PHP will accept.
post_max_size = 8M

mazazino
08-06-2007, 02:45 PM
Is this the line to set max file size?

ya thats the one



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum