how to restrict picture upload size for php
How do I restrict the picture size and where do I insert the code in? I can manage to upload pictures but it only can upload and display 4 pictures. what can I do to solve it开发者_运维问答?
When you upload files using PHP the information available while uploading is in array: $_FILES['image'] (image is the name of the file input in your form). This array contains some useful information: (copied from: http://php.net/manual/en/reserved.variables.files.php)
[name] => MyFile.txt (comes from the browser, so treat as tainted)
[type] => text/plain (not sure where it gets this from - assume the browser, so treat as tainted)
[tmp_name] => /tmp/php/php1h4j1o (could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
[error] => UPLOAD_ERR_OK (= 0)
[size] => 123 (the size in bytes)
[size] would give you the filesize in bytes. If you want to deal with the upload based on it's dimensions you will have to finish the upload first and then check dimensions using PHP function: getimagesize
精彩评论