Jump to content

[SOLVED] uploading only images


shadiadiph

Recommended Posts

This is just the extensio part of what I have.... If you can't figure out the rest,,, post your code that you have for your upload script. This will only allow .jpg ,,, you can add others.

<?php
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg"))
{
  Have your error here.
}

Just so you know,, this is far from secure from what I have heard. How,, I don't know.. Still learning myself

Link to comment
Share on other sites

Another option is to use the getimagesize function to validate if the file uploaded is indeed an image...

 

// validation... since this is an image upload script we should run a check 

// to make sure the uploaded file is in fact an image. Here is a simple check:

// getimagesize() returns false if the file tested is not an image.

@getimagesize($_FILES[$fieldname]['tmp_name'])

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.