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
Related
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/
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.
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.
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!
I can't figure out a good solution for limiting the storage amount a user may access with his files.
In the application users are allowed to upload a limit amount of files. The limitation is based on total file size. I.e. a user might be allowed to store 50 Mb on the server.
This number is stored in a database so that it can be easily increased/decreased.
The language used is PHP, but I guess the solution isn't depended on the scripting language.
Very sorry if the question is unclear. I don't really know what to ask for more than a strategy to implement.
Thanks!
Keeping track of how much space has been used should be straightforward - with each upload you could store the space used in another table. The PHP filesize() function will tell you the size of a file on disk. Use a SUM() SQL query to get the total size of all the files uploaded by each user, and compare it against their quota limit.
The tricky bit is when you're approaching the limit - you can't tell how big the file is going to be before it's uploaded. So you'll have to get the user to upload a file and then check its size and see if it takes them over quota. If the file's too big, delete and let the user know they're out of space.
A simple approach would be to store the filename, dates and sizes of a users uploads in the database too. Then you can easily reject an upload when it exceeds their total storage.
This also makes it easy to show a list of files sorted in a variety of ways, allowing a user close to their limit to select some files for removal.
You could even use the average size of the files the user uploads to warn them when they are getting close to using up all their space.
You can use a script (something like that) that iterates through a directory contents, calculates filesizes and then deletes files that don't fit or rejects new uploads. But I think that this better be done with some sort of directory restrictions on a server. Unfortunately, I'm not a linux guy, so I don't know exactly how to do that, but this post might be helpful.
Solution of drewm is good, I just want to add few words about tricky part he mentioned.
Yes, it is impossible to predict file size before file is uploaded, as you cannot check filesize using javascript on user`s file upload page. However you can do it using flash based file uploader (swfupload.org for example). By using it you can check files size before upload is started and check it against upload limit you have. This way you will save time for user (no need to upload file to get "limit exceed error" message).
As a bonus you can show user upload progress bar as well.
Don' forget about OS solutions. If the files are stored in a "user" specific directory, then you can use the OS to find the disk spaced used in that directory. A Linux solution would something like this:
$dirSize = explode("\t", `du -ks $userDir`); // Will return an array of size, dirName
if ($dirSize[0] > MAX_DIR_LIMIT) print "USER IS OVER QUOTA";