Results 1 to 5 of 5

Thread: PHP upload file (pics, in zipped format, rar file).

  1. #1
    Join Date
    Jul 2012

    Lightbulb PHP upload file (pics, in zipped format, rar file).

    I have some data to upload through php and the data could be in zipped or RAR format and file size could be more than 400MB. So i need some good code to work on this with minimum data loose and error.
    Could it be possible to upload such a large amount of data through php, if yes then i request to you please suggest some good stuff to use.


  2. #2
    Join Date
    Feb 2014
    You can upload large amounts of data, however, you need to configure the web server to allow it. If you're using Apache, you'll have to configure your php.ini file by going to the File Uploads section and change upload_max_filesize to the limit you want (it's a very good idea to have a limit). If you're not using Apache, you'll still have to configure it because the server will have a default which will definitely be well under 400 MB. After that, you should verify the uploaded file. I'm not sure how much you want so I'll give just a short bit of code from something I have lying around (note: for this I used a max file size of 200 MB but just change that to whatever max you want. It only accepts file size in terms of bytes, so use Google to convert your max to bytes). The below doesn't check whether the file already exists, I'm not sure what you entirely wanted so I didn't include it.

    With extremely large files, it's possible the upload may time out, in which case you may need to do more configuration to the php.ini file as well as .htaccess.

    The below code should be executed after the used has uploaded a file from a form.

    PHP Code:
    #array of case-sensitive file types that are not permitted
    $invalidTypes = array('air''app''bat''cgi''cmd''com''esh''exe''gadget''hta''jar''js''jse''jsx''pl'
    #checks if there is any error before uploading a file
    if($_FILES['file']['error'] != 0) {
    "Failure to upload due to error ".$_FILES['file']['error']);
    #checks if the user chose a file to upload before clicking "upload"
    if(!filesize($_FILES['file']['tmp_name'])) {
    "Please upload a file");
    #checks if the user's file is less than 200 MB /* change this part to whatever max file limit you want (highly recommended to have a limit!) 
    if($_FILES['file']['size'] > 209715200) {
    "File currently is ".$_FILES['file']['size']." but must be less than 200 MB");
    #updates file permissions
    chmod($_FILES['file']['tmp_name'], 777);
    $fileInfo pathinfo($_FILES['file']['name']);
    $fileExt $fileInfo["extension"];
    #checks whether the file is of a valid extension
    if(in_array($fileExt$invalidTypes)) {
    "The file type ".$fileExt." is not permitted");
    #retrieves the most recent date of file modification
    $fileDate date("d-m-Y, H:i:s"filemtime($_FILES['file']['tmp_name']));
    move_uploaded_file($_FILES['file']['tmp_name'], $targetPath)) { # targetPath is the path where it will be uploaded
        } else {

  3. #3
    Join Date
    Jul 2012
    Thanks For your reply.
    This a very helpful code for me. I only know how to change the limit in php.ini file but i am not aware of the .htaccess file. I will be very thankful to you, if you can suggest some for that too.
    as i mention the file would be zipped or rar file may be 400MB of above but less than 500MB.

  4. #4
    Join Date
    Jul 2012
    I have posted same in the other forum too, a guy reply something like this.
    PHP can upload as much file size as it can I believe. Your huge problem you will encounter on large file size is your php.ini or .htaccess. I have created my own "YouTube" sort of file uploading where you can only upload videos, but the file size are too large so I get the 413 error.

    I'm not sure if it'll help you, but you need to change the max_upload_size and max_upload_limit, but I've tried this and it still doesn't work. Tried it on .htaccess and it gives me error 500 apache misconfiguration.

    It's not working for me so I stopped building that application for a while now, but I'm certain that someone has gotten it to work. Your issue will probably be php.ini or .htaccess if you have access to either both of them.
    What could be the cause of these problem? would these will come while using the code you have given to me?
    suggest pls


  5. #5
    Join Date
    Feb 2014
    The first thing is to make sure that Apache was properly working and configured before you edited the php.ini file. With the code I provided, you need to have another page (can be purely HTML) that just takes in a file. If you don't have that then the code will not work. You should have something like the following, where verifyFile.php is the code I provided earlier. You also have to ensure you have a folder called "uploads" or whatever other name of your choosing in your htdocs folder as that is where the file will be uploaded to. The error you're getting is due to misconfiguring Apache and not a result of the code I provided below or in my previous post.

    If you cannot resolve your error by undoing whatever changes you did to your php.ini file, uninstall it and download the XAMPP installer (automatically does all the configuration, you just should create a back-up php.ini and modify the max_upload_size properties).

    HTML Code:
    <form enctype = "multipart/form-data" action = "verifyFile.php" method = "post">
    			<table border = "0" cellpadding = "2" cellspacing = "5">
    						<label for = "fileName">Select file to upload</label>
    						<input type = "file" name = "file" id = "fileName" placeholder = "Choose file path" autofocus = "autofocus" required = "required" />
    					<td><input type = "submit" value = "Load file" /></td>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10489 seconds
  • Memory Usage 2,895KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates