Images size and php upload - php

Thanks for reading this.
Ok here's my situation.
I have a website that let users upload a picture. I want to keep it kinda dumb proof so i tought that users could upload images right from ther digital camera. The problem is that my host have php set to accept a maximum of 2MB file upload. and a picture right out of a Digital Camera is doing about 10MB. How do i get these Jpeg images to shrink in size before getting on the server without making it to complicated for the users??
Could i treat the files with javascript on client side before it is uploaded? Or is there a really user friendly way of getting it done by the client??
Ideas and solutions are welcome.
Thanks.

You could try using an upload library like http://www.uploadify.com/ or http://swfupload.org/ that use Flash to upload files, which may circumvent the servers upload limit, but if those don't work, you might be stuck.

.htaccess would be your best solution, especially if you don't have access to PHP.ini. JS won't do what you want, however, Flash or Java applets could (in theory).
Here is the code required in a .htaccess file:
php_value post_max_size 10M
php_value upload_max_filesize 10M

You can't shrink it on the client's computer with PHP. In fact, PHP can't directly interact with the client machine (though it can generate JavaScript, which can).
PHP can not determine the filesize until it has been uploaded.
You may want to look at the Flash backed alternatives, which have greater privileges to this sort of information.

PHP resize image can be used in the server side.
http://php.net/manual/en/function.imagecopyresampled.php
http://www.php.net/manual/en/function.imagecopyresized.php

Related

Large file upload through Browser (100 GB)

Is there any way to upload large files (more than 80 Gb) through a web browser? Previously I have been uploading files (img, png, jpg) using plupload but it seems not to be working for larger files. I would also like to know how to implement a web page where users could upload like Mega.co.nz or Drive.google.com.
If it is impossible to do it using web development tools, can anyone guide me about how I can divide & upload a file in segments?
Thanks.
You can use the JavaScript Blob object to slice large files into smaller chunks and transfer these to the server to be merged together. This has the added benefit of being able to pause/resume downloads and indicate progress.
If you don't fancy doing it yourself there are existing solutions that use this approach. One example is HTML5 Uploader by Filkor.
If I was you I would use something like FTP to accomplish this. If you can use ASP.NET there are already good libraries that exist for file transfer.
Here is a post that shows an example of uploading a file: Upload file to ftp using c#
The catch is you will need a server. I suggest Filezilla. https://filezilla-project.org/

When using a flash uploader, do I have to change any php.ini settings?

I need to upload files that are up to 200 MB. I was told flash uploader is the way to go such as uploadify or swfupload. Do I have to change any php.ini settings for the uploader to work with large files such as 200MB? Any preventative measures that can be taken to make sure DDoS attack isn't something I'd encounter or make sure people are uploading trully 200 MB max filesize ? Using Cent OS 6, php 5.3
I am unsure how flash uploaders work since I have always tried to ingore them for the reason in my comment:
Just a note: Flash is deprecated on mobile devices now...so your
uploader won't work on iphone for one and flash has been taken off of
Android Market place last I checked.
Along with many others.
However it does actually upload to your server through PHP.
You will just need to as #NickRippe said set upload_max_filesize and you will also need to set max_post_size (though I am sure I read something about that too if I can find the link).
The other fields that most people talk about are not needed. I did some real digging when I came to do this and I found out from PHP mailing list and bug reports that 90% of the stuff people say isn't true.
Here are some that peple say you should set but you don't really need to:
max_execution_time
https://bugs.php.net/bug.php?id=16880, there are others like this where the community admit the execution has no effect until after upload.
memory_limit
Relationship between php’s memory_limit, upload_max_filesize and post_max_filesize there is also the bug report on this somewhere but can't find it now.
max_input_time
PHP file upload affected or not by max_input_time?
You need to edit the upload_max_filesize
upload_max_filesize = 200M
This should ensure no one can upload files over 200MB

(PHP) Is there any way to split a large file into packages for uploading it?

I've already checked post_max_size upload_max_filesize on my php.ini file, the thing is that my hosting provider doesn't allow more than 25M for each upload.
I need to let the users to upload files 50M - 100M. But before changing my provider I thought maybe there's some workaround to split large files into separate packages, upload them and then join them back together.
Any ideas will be appreciated :)
From Splitting a file before upload?
You can try [Plupload][1]. It can be configured to check whatever
runtime is available on users side, be it - Flash, Silverlight, HTML5,
Gears, etc, and use whichever satisfies required features first. Among
other things it supports image resizing (on users side, preserving
EXIF data(!)), stream and multipart upload, and chunking. Files can
be chunked on users side, and sent to a server-side handler
chunk-by-chunk (requires some additional care on server), so that big
files can be uploaded to a server having max filesize limit set to a
value much lower then their size, for example. And more.
Some runtimes support https I believe, some need testing. Anyway,
developers on there are quiet responsive these days. So you might at
least try ;)
[1]: http://www.plupload.com/index.php

php upload_max_filesize problem

am working on a website and i have a big problem when i tried to upload files, i increase upload_max_filesize and post_max_size and the code still understand only as a max. 10M. for any different folder php accepts 100M. but inside the site folder ( which am working inside) it doesn't understand it. i check for local php.ini or .htaccess.
note: am running a linux server.
For uploading bigger files I would suggest a dedicated uploader plug-in.
Like a SWF of Java. For these reasons:
Security - you can easily encode the sent data (encoding ByteArray in AS3.0 is very easy, can be even tokenized so it is hard to intercept the stream)
Reliability - with simple HTTP requests it is hard to actually monitor the upload progress, so the user might choose to close the uploaded (because he thinks it got stuck)
User friendly - again, progress bar
Not limited by server - if you accept it directly with PHP custom code, you won't need any configuring for annoying things like max file size on upload.
On server-side you will need either a Socket listener, or an HTTP tunnel if unavailable.
You can use JumpLoader, which is a Java applet, and it is able to split large files into partitions, and upload them one by one. Then a PHP script rebuilds the original file from the uploaded partitions on the server.
Plupload can split large files into smaller chunks. See the documentation.
Do you run Apache with mod_security? Then check if the LimitRequestBody is in affect.
Here is a good tutorial about Settings for uploading files with PHP.
Thanks guys,
I found the problem. i don't know why is the file is not visible for me /public_html/site/.htaccess
i tried to overwrite it, and it's seems to be working.
Thanks a lot for efforts.

Writing direct to disk with php

I would like to create an upload script that doesn't fall under the php upload limit.
There might be an occasion where I need to upload a 2GB, or larger file and I don't want to have to change the whole server execution to above 32MB.
Is there a way to write direct to disk from php?
What method might you propose someone would use to accomplish this? I have read around stack overflow but haven't quite found what I am looking to do.
The simple answer is you can't due to the way that apache handles post data.
If you're adamant to have larger file uploads and still use php for the backend you could write a simple file upload receiver using the php sockets api and run it as a standalone service. Some good details to be found at http://devzone.zend.com/article/1086#Heading8
Though this is an old post, you find it easily via google when looking for a solution to handle big file uploads with PHP.
I'm still not sure if file uploads that increase the memory limit are possible but I think there is a good chance that they are. While looking for a solution to this problem, I found contradicting sources. The PHP manual states
post_max_size: Sets max size of post data allowed.
This setting also affects file upload.
To upload large files, this value must
be larger than upload_max_filesize. If
memory limit is enabled by your
configure script, memory_limit also
affects file uploading. Generally
speaking, memory_limit should be
larger than post_max_size. (http://php.net/manual/en/ini.core.php)
...which implies that your memory limit should be larger than the file you want to upload. However, another user (ragtime at alice-dsl dot com) at php.net states:
I don't believe the myth that 'memory_size' should be the size of
the uploaded file. The files are
definitely not kept in memory...
instead uploaded chunks of 1MB each
are stored under /var/tmp and later on
rebuild under /tmp before moving to
the web/user space.
I'm running a linux-box with only 64MB
RAM, setting the memory_limit to 16MB
and uploading files of sizes about
100MB is no problem at all! (http://php.net/manual/en/features.file-upload.php)
He reports some other related problems with the garbage collector but also states how they can be solved. If that is true, the uploaded file size may well increase the memory limit. (Note, however, that another thing might be to process the uploaded file - then you might have to load it into memory)
I'm writing this before I tried handling large file uploads with PHP myself since I'm evaluating using php or python for this task.
You can do some interesting things based around PHP's sockets. Have you considered writing an applet in Java to upload the file to a listening PHP daemon? This probably won't work on most professional hosting providers, but if you're running your own server, you could make it work. Consider the following sequence:
Applet starts up, sends a request to PHP to open a listening socket
(You'll probably have to write a basic web browser in Java to make this work)
Java Applet reads the file from the file system and uploads it to PHP through the socket that was created in step 1.
Not the cleanest way to do it, but if you disable the PHP script timeout in your php.ini file, then you could make something work.
It isn't possible to upload a file larger than PHP allowed limits with PHP, it's that simple.
Possible workarounds include using a client-side technology - like Java, not sure if Flash and Javascript can do this - to "split" the original file in smaller chunks.

Categories