ok i have a script that uploads images. I have a script that checks the file size and if it is too big it doesnt upload it. But it seems to upload the whole image into memory b4 it determines if it too big. Is there any way to check the file sizes b4 it is uploaded into memory? I have 12 fields and I have the image size limit at 1.5mb. so if they tried to upload 12 1.6mb files it would take 10 minutes and then not do any uploading. I would like to loop thru the files and determine if they are too big b4 any of my resources are used up. Am i explaining this well? I am going to put a big warning on the page. But i would like to idiot proof it. thanks
Actually, I think you meant the size in kb. $_FILES['name']['size'] will output the KB size of the image. Do basic math calculations to find MB or whatever you need.
I am using that to determine the file size in kb and i have a max file size that I compare it to. but as I was saying. It seems to upload the whole image b4 it determines if it is too big. I am testing onefile that is 1.6 mb and it takes about 20 seconds to continue with the script. I am looking for instant confirmation b4 it is uploaded into memory. Is this possible?
You mean before it uploads a temporary image or final? The final upload is initiated by you using move_uploaded_file(), so it must be an error in your coding.
If you want to check the filesize before upload, you need to look at either some javascript or flash on the client entd. The best way to do this is probably to use a flash uploader as many clients ignore javascript, thus defeating your system. Check out swfupload.mammon.se. I don't have enough posts to post that as a link
To check image size before uploading, you can try this: $nPhotoSize = $_FILES['photo']['size']; // size of uploaded file if ($nPhotoSize == 0) // if there is no image selected { die ("Sorry. The upload of $sPhotoFileName has failed. Search a photo smaller than 100K."); } if ($nPhotoSize > 102400) // if image is larger than 100 kb { die ("Sorry. The file $sPhotoFileName is larger than 100K. Advice: reduce the photo using a drawing tool."); } else { <!-- paste image uploading code here--> }
$filesize = $_FILE['file']['size']; or <?php // outputs e.g. somefile.txt: 1024 bytes $filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes'; ?>