Re: substr?

From: Date: Tue, 17 Jun 2008 13:15:14 +0000
Subject: Re: substr?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-275481@lists.php.net to get a copy of this message
On 17 Jun 2008, at 14:05, Jason Pruim wrote:
On Jun 17, 2008, at 8:46 AM, Stut wrote:
On 17 Jun 2008, at 13:39, Jason Pruim wrote:
I am attempting to adopt some code to work more reliably then how it is now... What I am doing is coding a upload form where people could be uploading .zip files in excess of 200 MB... Yes I know that is large, but it's for a print shop and they get HUGE files to print from. The code I'm having issues with is this: $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. All I want to do is grab the file extension and verify that it is a .zip or a .pdf etc. file. This is working for small files (under a few megs) but for some reason it fails when I get bigger. I have increased the allowed memory size to 50 MB's I'm testing with a 44 MB file right now. When it fails, it says the file type is not allowed even though it is listed in the file type array. Hopefully I have given you enough to go on to at least ask me some questions :)
Sounds like you haven't increased upload_max_filesize in php.ini. If you actually look at what's in $_FILES['userfile'] you'll see most of it's empty. I suggest you add some more error checking rather than assuming everything worked ok.
Hey Stut, I'm looking into that now, i just increased the php.ini upload_max_filesize to 250M and tried uploading a 44MB file and it failed... I'll try and add some more error checking, but I'm really leaning towards the problem being in the code I posted... But please, prove me wrong! :)
Did you restart the web server after changing it? Are you sure you're editing the right php.ini? There's nothing wrong with our code that I can see. On an efficiency note you don't need the last parameter to substr - if it's omitted it defaults to the remaining test. I would suggest doing a var_dump on $_FILES['userfile'] before the code you've posted to check it contains the right stuff. If not then it's the upload that's failing and nothing in your code. -Stut -- http://stut.net/

« previous php.general (#275481) next »