Re: substr?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17 Jun 2008, at 14:04, Jason Pruim wrote:
On Jun 17, 2008, at 9:01 AM, Dan Shirah wrote:
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.

I'm not an expert on pulling in and reading files, but if all you want is the last three characters of a file name, couldn't you just do something like:

$extension = substr($filename, -3);

if ($extension = "pdf" || $extension = "zip") {
 echo "The file is a PDF or ZIP.";
} else {
 echo "Incorrect file type.";
}

??

Or maybe you are saying you want it to perform this check while the user is attempting to upload the file and not after it has been uploaded?

I am looking to use this as a simple test prior to the upload beginning... IE, if it's not a .zip file, don't try and upload 250MB files :)

That code will not be executed until the file has been uploaded. Such is the nature of the beast.

If you really need to do this your best bet is to use a client-side uploader.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux