Jump to content

.image


almightyegg

Recommended Posts

<?
$file = '/home/lordofth/public_html/images/society/banner'.$clutch[id].'.gif';

if(file_exists($file)){
echo "<img src='http://www.lordoftheabyss.com/images/society/banner$clutch[id].gif'>";
}else{
echo "<img src='http://www.lordoftheabyss.com/images/society/bannerdefault.gif'>";
}

 

The problem I have is that the leader/coleader can upload a new banner, but I don't want to have to restrict it to .gif but in saying that I don't want to have to run 20 different checks for .jpg .png.bmp etc...

 

so is there a variable that I can put like:

$file = '/home/lordofth/public_html/images/society/banner'.$clutch[id].'$IMAGE_ENDING';

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/45737-image/
Share on other sites

so is there a variable that I can put like:

$file = '/home/lordofth/public_html/images/society/banner'.$clutch[id].'$IMAGE_ENDING';

 

Why don't you save the filename and extension together, for example: $clutch[id] = happyface.gif or happyface.jpg, etc. then you can forget about the $IMAGE_ENDING altogether.

Link to comment
https://forums.phpfreaks.com/topic/45737-image/#findComment-222195
Share on other sites

Someone uploades a file, right?

Now you got a filename like my_picture.jpg.

So let's put that string into a variable and filter the type of it (.jpg):

<?php
$file = 'my_picture.jpg';
preg_match('{(\.[\w\d]+)$}', $file, $match);
$file_type = $match[1]; // result: .jpg
?>

Now you can save $file_type in your mysql an write it out, like the filename

Link to comment
https://forums.phpfreaks.com/topic/45737-image/#findComment-226650
Share on other sites

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.