开发者

Overcome host's max file size limit for PHP/POST data when uploading files?

开发者 https://www.devze.com 2023-02-08 17:50 出处:网络
I\'m with a fairly mediocre low-cost (shared) host at the moment (as it\'s all I can afford just now) and want to implement a very basic file upload feature on a page. I want to allow files of up to 1

I'm with a fairly mediocre low-cost (shared) host at the moment (as it's all I can afford just now) and want to implement a very basic file upload feature on a page. I want to allow files of up to 100MB to be uploaded to the server but my free host limits the PHP_MAX_FILESIZE to 32MB and开发者_如何学Python the POST_FILESIZE to 64MB.

Is there any way of overcoming this without requiring the user to split the larger files into smaller chunks? Either a JavaScript or Flash-based solution which could perhaps somehow route parts of the file through different HTTP requests or some other way to get around the 32MB limit?

Or are there any commands I can attempt to make which might over-ride the host's limits? I've already tried using .htaccess without success. EDIT: also tried ini_set. I'm thinking the only way is some kind of chunking/splitting/multi-streaming or another way to solve the inability to set higher PHP values.

Any suggestions are hugely appreciated. Thanks.


You can use Flash. Start with this: http://soenkerohde.com/2010/01/chunk-file-upload/

OR

use https://github.com/moxiecode/plupload


might also possibly be able to use ini_set('upload_max_filesize','100M');

But I have a sneaking suspicion that your host might not be happy with you trying to circumvent their limit...


if your 'free host' already limits you, there is nothing you can do about it. try reading

http://www.php.net/manual/en/ini.core.php#ini.post-max-size

and

http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize

here is where you can set it during runtime (ini_set) or not

http://www.php.net/manual/en/configuration.changes.modes.php

i suggest you just do multiple file uploads. 100 mb right? are you planning to host videos and movies? try looking for a better paid host rather than free ones :)


if your host allows java applet then in sourceforge there is already package for it. which allows you to dw file via java applet from users machine to your host via small packages. it works because applet handles the file upload code in users machine and at server side you will receive small chunks which you can bind later and any file size can be uploaded.

i found the link here it is, http://sourceforge.net/projects/juploader/


Some hosts allow using a local copy of php.ini (mine does, for example), so you could change parameters at will. Keep in mind that 100MB each file can rapidly bloat your host, expecially if it's not top of the category, so be careful.


Since ini_set doesn't seem to be working, you could try and set it via the .htaccess file. I'm not sure about the exact syntax but it's something involving php_flag. I wouldn't be surprised if this doesn't work either.

From my experience choosing a good host based on their advertising is impossible. I know of no other way than to simply try out a bunch and hope your run across one that isn't super retentive.

Upload limits are a common problem. If it's common for your customers to upload very large files then perhaps it would be wise to look into some other hosting plan. If it's not very common at all you could just have them send you the file so you can FTP it. Sometimes the best solution is the simplest solution.


You could have your users upload to an outside site. Then give you the URL from that outside site. If you have enough space, you can circumvent how long the outside site keeps the file by downloading it to a directory in your site. It's certainly not the best option, but your users will have a bigger upload quota and probably faster upload speeds (shared servers and speed mix like oil and water).


Abstract:

1) Read the file before to sending it (catch into onsubmit event); split and send the chunks as textarea fields.

2) In the server side, recover the chunks, and make one single file.

Proposal:

Depending on the environment in which your script runs and where the file resides, your options include the following:

 XMLHttpRequest

object (for reading files available via URLs on your website)

 FileSystemObject

(if you use Windows Scripting Host or Internet Explorer in a trusted environment) a "helper" Java applet that reads a file or URL for your script.

(Extract from http://www.javascripter.net/faq/reading2.htm)

If ok, remove the input file element of the form.

Then, split the string into many chunks.

mySplitResult = myReadedDocument.split( 1024 * 1024 ); // 1M each

That make an array of pieces of your document:

Add the values into the form (remember set the same name with [] to all the new controls). Assume that form id is 'myForm':

formName = document.getElementById('myForm');

mySplitResult.forEach(function(item) {     
    ta = document.createElement('textarea');
    ta.appendChild(document.createTextNode(item))
    ta.setAttribute("name", "chunk[]" );
    formName.appendChild(ta);

});

In the server side, you can reconstruct the chunks and save as a file.

<?php
    $chunks = $_POST['chunk'];
    $fileContent = implode( '', $chunks );
    file_put_content( 'dirname/filename.foo', $fileContent );
?>

The weight of success is that you can read the file on the client side.

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消