Jump to content

Checking Uploaded Files


kc9ddi

Recommended Posts

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
Share on other sites

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
Share on other sites

Im not sure, but I don't think that it is a temoprary directory, I think that
it is just memory storage.  Any who... Here try this:
[CODE]
<?php
if ($_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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.