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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.