Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    uploading large files in php

    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?

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    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).
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    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
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #5
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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...mitrequestbody
    Last edited by JamieR; 08-07-2007 at 01:24 AM.

  • #6
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    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..

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    All the PHP settings that affect the maximum upload size are settable in php.ini or a .htaccess file.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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);

  • #9
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting the complete path name for a file in $_FILES

    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

  • #10
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Is this the line to set max file size?

    ; Maximum size of POST data that PHP will accept.
    post_max_size = 8M
    You can not say you know how to do something, until you can teach it to someone else.

  • #11
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by timgolding View Post
    Is this the line to set max file size?
    ya thats the one


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •