kc9ddi Posted November 28, 2006 Share Posted November 28, 2006 Hi -I'm writing a simple program that lets users upload images to a server. I only want them to be able to upload .gif, .png and .jpg. I wrote a simple function that will check a file's MIME type, and return the appropriate extension. I'm wondering how I could determine the path where the temporary files are stored, so I could do this check before I move the file to its permanent home. Obviously, I could figure it out for one server and hard-code it in, but I'm hoping there's a way to determine it within the script. Is this possible?Thanks Link to comment https://forums.phpfreaks.com/topic/28750-checking-uploaded-files/ Share on other sites More sharing options...
The Little Guy Posted November 28, 2006 Share Posted November 28, 2006 http://us3.php.net/getimagesize[quote=PHP.net]Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.[/quote]Just compaire the numbers in your PHP code and if it isn't a match, don't allow upload. Link to comment https://forums.phpfreaks.com/topic/28750-checking-uploaded-files/#findComment-131603 Share on other sites More sharing options...
kc9ddi Posted November 28, 2006 Author Share Posted November 28, 2006 That's a good idea, but I still don't know how to check the file in its temporary directory... Link to comment https://forums.phpfreaks.com/topic/28750-checking-uploaded-files/#findComment-131610 Share on other sites More sharing options...
The Little Guy Posted November 28, 2006 Share Posted November 28, 2006 Im not sure, but I don't think that it is a temoprary directory, I think thatit is just memory storage. Any who... Here try this:[CODE]<?phpif ($_FILES['file_name']['type'] != 'image/gif' || $_FILES['file_name']['type'] != 'image/jpg'){ echo'You can not upload that file type';}else{ #upload file script...}?>[/CODE] Link to comment https://forums.phpfreaks.com/topic/28750-checking-uploaded-files/#findComment-131639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.