Multi part file uploading method - php

Im trying to upload faster. My connection upload limit is ~2Mbit and upload speed is ~200Kb. When i try to upload 10Mb file, it finished ~50 secs. I want to do faster.
Is there any method like that multi part file uploading. For example process:
Select file (10000Kb)
Submit form
Split into pieces the file (100kb x 100 pieces)
Upload them all at once
Merge pieces and save the file
This upload method is possible? I read about Content-Range and Chunked file uploads but i did not know exactly where to look.
Is that may guide me in this regard? Or does anyone know of an alternative fast upload method?

Jumploader does partitioned uploads. I'm not quite sure, if these are simultaneous or not.
http://jumploader.com/

Related

How to upload larger file than upload limit of my hosting provider?

I have hosted a domain name on a cheap hosting website. This website allows uploading only the files less than 50 MB. I want to upload larger files. Is there any working trick without changing in php.ini. because it's not possible for me.
There isn't really an easy way round this. A couple of suggestions:
Resize images to make them smaller using Javascript before uploading. You can use a filereader and then a canvas to resize the image.
If you really need them that big then split the images up into chunks, again using a filereader to get the file into Javascript, then extract the data in chunks and upload each chunk separately. You'd need some clever PHP code to stick the chunks back together again. I would add some kind of chunk index into each upload as you can't guarantee the chunks will arrive in order.
Since the max upload size is limited to 50MB you can't do it this way , unless , you can split the file into files less than 50MB and upload each one .
To implement this solution of spliting file into many parts , use phpfsplit
You can also use the plupload

Continuous image upload without relying on max_execution_time?

We're developing a website where users may change their slider images. (fullscreen slider) Each image is around 2000px to 2000px and we allow users to upload as many images as they want in our HTML form (capped to 10).
Their upload speed will be pretty slow and I believe we'll easily pass the max_execution_time of PHP which is default to 30 seconds. We will also let users to upload some .rar/.zip files in the future capping at 100MB.
We had few ideas but I wanted to ask SO for a better solution/reviews.
We can change 30 seconds for alot higher value since we have access to PHP.ini and let users upload all images at once, but that may create performance related issues in long term. (This is not an option!)
We can make use of javascript in client size. Foreach image paths specified in HTML form, javascript may post it with XMLHttpRequest one by one and expect a response. If the response is true, javascript moves to the next images and attempts to upload it. (Profit: each image will start php itself and get their own 30 seconds lifetime.)
Javascript solution won't work in file uploads when the file is above 50MB. Customers are usually capping at 25kbps upload speed in target region so there is no way they can upload 50MB in 30 seconds. Similar to #2, we may use a script where uploaded file saves in bytes every 30 seconds and client continues to push remaining bytes, or anything alike.
Basically, how would you complete this task?
We don't want to rely on PHP.ini, so increasing max_execution_time shouldn't be an option.
Should we go with #2 for image uploads and what can you suggest for #3?
Take a look into chunked uploads.
You'll need to use some sort of uploader script like JUpload or plUpload. You can specify how large the chunk of a file should be sent to the server. For example, if you have a 10MB file, you can chunk it to 1MB, so 10 1MB chunks would be uploaded to the server. In the case of a slow connection, just make the chunks smaller like 500KB.

Want partial upload of large file. HTML / PHP

I want to have php script that uploads partial files. Like the first 1 MB of a very large file. Can this be done in PHP with a regular form upload? Like, it close off the connection after 1mb upload...
I've looked a lot of uploaders (html5/javascript/flash), and it seems some support 'chunking', and file size limits which sounds 1/2 of what I want.. but I'd of course somehow need to know that it's only a partial of a full file.
If you are open to using javascript you can read the file into a blob on the client (which is far quicker than uploading), cut out everything after the first 1mb, and send it to php via ajax. It wouldn't technically be a traditional php upload form, but it would seem like one to the user.

Count and limit the number of files uploaded (HTML file input)

I have that basic, well known multiple file upload form. Something like that...
<input type="file" multiple="multiple" name="something[]" />
Is there a way (preferable a hard coded option) to limit the number of files that user can select? By limit i mean strictly blocked, not just a warning if number is exceeded.
Thanks in advance. :)
You can implement a javascript solution to check the number of files that have been selected, which you can then use to forbid uploading to the server. There are really only going to be client-side solutions to this problem though, as there is really nothing stopping a user from posting these files to your php script anyway. You can specify a maximum upload size limit, but it isn't specific to the number of files that are being uploaded.
Your best bet is to implement some javascript checking, specifying a reasonable maximum upload size for your http server (or in PHP), and then ignoring any file uploaded if it exceeds your maximum count.
Read about the HTML5 File API here to restrict the count of selected files: http://dev.w3.org/2006/webapi/FileAPI/
Here is the php.ini docs which explain how to make a size limitation on uploads: http://php.net/manual/en/ini.core.php
As was suggested in the comments, check out: http://php.net/manual/en/ini.core.php#ini.max-file-uploads
we all know that in an array first element is stored in 0 th index, 2nd in 1st index......nth in (n-1)th index
now you cant take count($_FILES['something']) which will always return 5 since there are 5 keys in the array
now the question is what does $_FILES['something']['name'][0] contains? => name of first file uploaded
so check like
if(empty($_FILES['something']['name'][0]))
{
//checking whether a single file uploaded or not
//if enters here means no file uploaded
//so if you want you may put a check/validation here to make file
//upload a must in your website
}
if(isset($_FILES['something']['name'][5]))
{
//checking whether 6 files uploaded or not
//so here you can put a check/validation to restrict user from
//uploading more than 5 files
}
Pure Js alternatives that do that and much more:
FineUploader. Demo
bluimp's jQuery File Upload Plugin. Usage: jquery file upload restricting number of files
They are also available at https://cdnjs.com/
Some plugins seem to assist with this, such as: Uploadify (flash based). However I haven't used this one or others enough to know if they how restricting they can limit uploads.
More info on Uploadify Multiple Uploads.

How to make a gigantic PDF with TCPDF with a limited timeout

I need to do a PHP site where a lot of pictures can be put together to make a big PDF file. This can be easily done with TCPCDF... but the problem is that I dont have access to the PHP timeout on the server.
I though that could be interesting make one page at the time, using AJAX, so the client can receive a response in a short time, and finally merge all the pdf files with some library... but then i though: "Emiliano! wouldn't be the same? Because, if i try to merge 100 1mb files; when I reach file 99, it would be merging a 99mb file with a 1 mb file... timeout secure?
So... any suggestions? Maybe Im wrong about the merging and a 99mb pdf & 1mb file would be a fast transaction?
Thanks in advance!

Categories