Uploading large files with PHP

19 replies
Hi. I have a requirement where the client needs to upload files of approx 100MB frequently. What is the quickest and the best way to do it without getting all the timeout errors?
#files #large #php #uploading
  • Profile picture of the author paparts
    For me go edit the php.ini file an edit the max upload size.
    {{ DiscussionBoard.errors[2679547].message }}
    • Profile picture of the author margaritamaker
      why you not use file sharing hosting? instead save it to your own server? because it really consume huge bandwidth
      {{ DiscussionBoard.errors[2785868].message }}
  • Profile picture of the author ram07
    1.) The php.ini files need to be have all overrides as talked about before
    a.) upload_max_filesize = 100MB
    b.) max_execution_time = -1 or 18000 (18000 = 5 hours)
    c.) memory = upload_max_filesize

    you can do most of the switches on a one time basis like the following:
    add to the top of your php file before
    -----------------------------------------
    ini_set('max_execution_time','18000');
    ini_set('upload_max_filesize','50');
    init_set('max_input_time','-1'); // -1 is equiv to infinite
    ini_set('memory_limit','50');

    The code above will switch the settings as you need them switched, however safe_mode must be set to off.
    additionally you need to make sure the file_uploads is turned on, as silly as this sounds this is the big problem for a lot of people.

    Thank you
    {{ DiscussionBoard.errors[2680871].message }}
  • Profile picture of the author Shounak Gupte
    should i use a simple upload script after playing with the php.ini file?
    Signature
    Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
    {{ DiscussionBoard.errors[2687778].message }}
  • Profile picture of the author jminkler
    You should use scp or ftp ... i mean depending on the requirements, they could have a folder on thier local machine that gets checked every so often but uses FTP to transfer the files instead of a clunky web interface
    {{ DiscussionBoard.errors[2688969].message }}
    • Profile picture of the author ramsarvan
      hi,
      This is because of your execution time .
      set your execution time in your .ini file with maximum time. that will do it.
      {{ DiscussionBoard.errors[2690049].message }}
  • Profile picture of the author zeeshi570
    Hi,

    here is a solution which u can implement without operating your php.ini

    Past these two lines of code at start of script

    set_time_limit (0);
    ini_set('memory_limit', '2048M');

    Cheers
    {{ DiscussionBoard.errors[2691043].message }}
    • Profile picture of the author Shounak Gupte
      Originally Posted by zeeshi570 View Post

      Hi,

      here is a solution which u can implement without operating your php.ini

      Past these two lines of code at start of script

      set_time_limit (0);
      ini_set('memory_limit', '2048M');

      Cheers
      and then should i use normal php upload? or some ajax? or anything i want?
      Signature
      Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
      {{ DiscussionBoard.errors[2708181].message }}
      • Profile picture of the author jernej
        Originally Posted by Shounak Gupte View Post

        and then should i use normal php upload? or some ajax? or anything i want?
        normal php should work if apache is configured correctly.

        but if you can, use other methods (such as ftp or sftp, or even a python script really) to upload large files to the server.
        {{ DiscussionBoard.errors[2787075].message }}
  • Profile picture of the author SteveJohnson
    Neither Apache or PHP were designed to handle large file uploads. You should be using a perl/python script on your server. Google is your friend on this one.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[2709593].message }}
  • Profile picture of the author circus_freak
    Originally Posted by Shounak Gupte View Post

    Hi. I have a requirement where the client needs to upload files of approx 100MB frequently. What is the quickest and the best way to do it without getting all the timeout errors?
    create ftp client user in cpanel. And client can upload via filezila
    {{ DiscussionBoard.errors[2709911].message }}
    • Profile picture of the author thedigitalshopper
      Create a .htaccess file in the root folder of web server.
      Put the following code in side the .htaccess file and save it.
      php_value upload_max_filesize 20M
      php_value post_max_size 20M
      php_value max_execution_time 200
      php_value max_input_time 200

      Now you can upload the file-size up-to 20MB in a simple way using file field in your html form and move_uploaded_file() function available in PHP. In the above .htaccess file, uploading capability is increased by the four parameter first one is maximum file size for uploading, second one is maximum size of the post data , third one is maximum time in seconds a script is allowed to run before it is terminated by the parser and last one is maximum time in seconds a script is allowed to parse input data such as like file uploads, POST and GET data.
      {{ DiscussionBoard.errors[2709970].message }}
  • Profile picture of the author Darren Mothersele
    As well as making the requisite changes to php.ini you could also enable the PECL uploadprogress library. This allows you to monitor the file upload progress from your PHP script.
    {{ DiscussionBoard.errors[2792479].message }}
  • Profile picture of the author Shounak Gupte
    it is a transcription website... so creating FTP accounts for all clients isnt possible. anyone has any examples of the script i can use?
    Signature
    Looking for a quality but affordable graphic designer to partner with. To express your interest PM me with some samples.
    {{ DiscussionBoard.errors[2803826].message }}
    • Profile picture of the author raj23
      Hi,
      you can use this command in your php file.
      PHP Code:
      ini_set("memory_limit","100M"); 
      and make this changes in /etc/my.cnf (mysql's config file)
      Code:
      set-variable = max_allowed_packet=100M
      {{ DiscussionBoard.errors[3257490].message }}
  • Profile picture of the author dholowiski
    I would recommend using a Java - not Java Script and/or Silverlight file uploader. You could also have FTP accounts automatically created when a user creates an account on your web site.

    Every site that I can think of that lets you upload 100MB+ files uses one of these two options (other than Bit Torrent).

    Basically, using PHP to upload 100MB files is really pushing the limits of PHP. If there is one tiny little hiccup during the upload everything dies and the user has to start all over again. As Darren mentioned, you have to enable the 'PECL uploadprogress library' to even allow a progress bar in PHP.

    I would just head over to Elance and hire a programmer to set up a java or silverlight uploader for you.
    Signature

    Immediate notifications when someone visits your web site. Free WordPress Plugin
    onepix.me

    {{ DiscussionBoard.errors[2823635].message }}
  • Profile picture of the author phpbbxpert
    Before you get as far as hiring a programmer, I suggest seeing what is available on your hosting account.
    SilverLight is Windows servers.
    And Java is not usually available by default with most hosts.
    {{ DiscussionBoard.errors[2823684].message }}
  • Profile picture of the author dholowiski
    A Java Applet running on the client side (in the user's web browser) can upload by just about any method you program it to - including PHP, FTP and HTTP - the client side does the hard work, so the programmer would create an app that uses whatever file upload methods the server supports (you don't need to run Java on the server). Yes - silverlight requires a windows server, but it's a nice fallback in case the user doesn't have Java installed.
    Signature

    Immediate notifications when someone visits your web site. Free WordPress Plugin
    onepix.me

    {{ DiscussionBoard.errors[2823729].message }}
    • Profile picture of the author msforum01
      very interesting topic.... keep it up guys....
      {{ DiscussionBoard.errors[3162632].message }}

Trending Topics