Jump to content


Photo

Changing a filename


  • Please log in to reply
3 replies to this topic

#1 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 04 June 2006 - 04:07 AM

I have the following code to change a filename when I am creating a thumbnail on upload:
$file = "something.jpg";
$tb_image = explode(".", $file);
$array = array($tb_image[0], 'tb.jpg');
$together = implode("_", $array);

I am curious, is there a better way than exploding the name to insert the "_tb" into the middle of the name?

DDM
[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 04 June 2006 - 04:13 AM

Use eregi_replace.
ex

$file = thumb.jpg
$thumbnail = eregi_replace ('.jpg', '_tb.jpg', $file);

you can read more about eregi_replace here:
[a href=\"http://us2.php.net/eregi_replace\" target=\"_blank\"]http://us2.php.net/eregi_replace[/a]
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 04 June 2006 - 05:01 AM

Awesome!

I knew there had to be a better, cleaner way of writing this out. Thank you very much.

DDM

[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]

#4 DapperDanMan

DapperDanMan
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 04 June 2006 - 07:36 AM

Awesome!

I knew there had to be a better, cleaner way of writing this out. Thank you very much.

DDM

[a href="http://www.brierrowstudio.com" target="_blank"]http://www.brierrowstudio.com[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users