Jump to content

Displaying image regardless of extension


perky416

Recommended Posts

Hi everyone,

 

Sorry not sure if this is a php or html problem.

 

Im using php and a html form to upload images to my site, i have made it so that jpg, jpeg, gif and png images can be uploaded. The problem im having is displaying the image.

 

<img src="images/<?php echo $name ?>.jpg" />

 

That works fine if a jpg was uploaded, but what if a png or a gif was uploaded? The $name is going to be unique, there will not be more than one image with the same name, so what do i have to do to display the image regardless of what the extension is?

 

Thanks

Link to comment
Share on other sites

Not the complete code but this will get your extension and as you can see limit the uploads to just those extensions. This is php:

 

 

if (!empty($_FILES["image"]["name"]))

{

$image=$_FILES['image']['name'];

$filename = stripslashes($_FILES["image"]["name"]);

$extension = getExtension($filename);

$extension = strtolower($extension);

if(($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))

{

$hidden_text = '  Not a valid image format, only use .png, .gif, or .jpg!';

//extension is okay

}else

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.