shinokage — 2010-12-26T20:22:47-05:00 — #1
Okay so imagecopyresampled().... let's say I just uploaded the file funnycat.jpg, so for the thumbnail I want to call it funnycatthm.jpg. How would I do that??? When you get the filename it automatically includes the extension. But it (http://www.php.net/manual/en/function.imagecopyresampled.php) says to enter the "Destination image link resource" as a parameter. So that means the entire file name (directories included and all, like site.com/images/coolstuff/funnycat.jpg), right? So how the heck do I add something before the extension to give the new file a name? :sick: I'm so confused.
Any help with this would be immensely appreciated.
system — 2010-12-26T20:34:10-05:00 — #2
You can use imagejpeg to output a jpg file to whatever file name you like.
shinokage — 2010-12-27T23:06:19-05:00 — #3
Well, I understand that I can give it whatever name I want, but the images that are upload have file names that are generated for them, so I would like to just be able to tack something onto the end of it (such as 'thm'), I want to know if it's possible to do that.
Is there a way for it to tell me what the extension is? Even that would be helpful (since, for example JPEGs can be either jpg or jpeg), because then I could just take off the file extension, add what I want, and then stick it back on....
system — 2010-12-27T23:12:42-05:00 — #4
What is the code that generates the file names for the uploaded files? I would think you should be able to adjust that code to add 'thm' to the file name.
shinokage — 2010-12-29T16:37:09-05:00 — #5
$now = time();
while (file_exists($uploadFileName = $uploaddir . $now . '-' . $_FILES['file']['name']))
That's the code, but I was just thinking that I can just add what I want to the beginning instead of the end ^_^; -sigh- My problems are always so simple to solve.
scallioxtx — 2011-01-01T20:04:57-05:00 — #6
What you want to do is separate the filename bit from the extension, append what you want to the filename, and then glue them back together. Like so:
// assume uploaded file
// get the position of the last (!) dot in the filename
// get the file name
$name=substr($filename, 0, $pos);
// get the extension
$ext=substr($filename, $pos + 1);
// set the new name
// glue back together
Note that this uses $ext without the dot in the extension, which makes it easer if you want to check the extension later; 'jpg' is easier to read and type than '.jpg'
shinokage — 2011-01-08T23:29:04-05:00 — #7
Ooooooh; I knew there must've been a way to do that. Thank you!!!