Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Renaming an Attachment inside an object?

Quote Reply
Renaming an Attachment inside an object?
Hi,

Is it possible to rename an attachment once it's inside a mail object? For example, with the attachment below, once I've passed it the path and name of the original file, can I get into the object and change the file name to "fred.jpg" instead of being "12587.jpg".?

$mail->attach (
type => 'image/jpeg',
encoding => '-guess',
body_path => '/path/to/image',
filename => "12587.jpg"
);

Cheers,
R.

Quote Reply
Re: Renaming an Attachment inside an object? In reply to
Possibly, but why? Naming the file as the username would cause integrity problems. Using a unique incremented number is much better.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Renaming an Attachment inside an object? In reply to
Hi Eliot,

"fred.jpg" was just an example, not any particular username.

It could as easily be dog.jpg, happy.jpg, awszwry.jpg etc.

When the file gets created it's getting a temporary reference name that looks like this "q32dtfAec34455cdie11cCedesSss2.jpg" so I just want to tidy it up and give it a generic name like "yourfile.jpg".

Cheers,
R.


Quote Reply
Re: Renaming an Attachment inside an object? In reply to
You will still run into normalization problems by allowing users to rename the file name because users could possibly name their files the same. And if you allow multiple file uploads at some point, then the files will be overwritten. It would entail more works than its worth, IMHO.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Renaming an Attachment inside an object? In reply to
Hi Eliot,

I see what you're getting at, but the user problems don't really apply in this situation.

What happens is this...

A user chooses a link in the directory. A different script then automatically selects the image associated with that link and manipulates it, saving the altered image with a unique filename like SxfFEeg1scAaqibc4uycD.jpg into a temp directory. The altered image is also displayed to the user.

If the user likes that image, they press send. The script then grabs the temp image, automatically gives it a nice name, and posts it off. The nice name will be the same on all outgoing images, and hard set in the script - the user doesn't choose it.

Hope that makes sense.

You don't know if one of the GT functions will enable me to change it do you? I can't seem to find one anywhere.

Cheers,
R.


Quote Reply
Re: Renaming an Attachment inside an object? In reply to
Thanks to Alex for answering this one! :)

The 'filename' section of the attach function is where you can specify an alternative name for the file included in the email. My problem was I thought the body_path was only the path to the original file, and filename was the name of the original file I wanted to send.

The correct way is the fully reference the original file in the body_path call, and then do as you please with the filename part of it! :)


# Add the jpeg attachment to it
$mail->attach (
type => 'image/jpeg',
encoding => '-guess',
body_path => '/path/to/image/original.jpg',
filename => "newname.jpg"
);
# send the file
$mail->send() or die "Error sending mail.\n\n";


Hope that helps someone!

Cheers,
Regan.