+ Reply to Thread
Results 1 to 5 of 5

Thread: file_names and template question

  1. #1
    Join Date
    Jul 2007
    Posts
    4

    Default file_names and template question

    I love this script and the ease of use. I figure the support fee is well worth use of the script.

    Here is my question that I hope has a really simple fix. I'm setting up my form to allowing posting of files. I have it setup in the hidden field where the files that are uploaded have the %date% value before the file name. I want to have the full file name with date display in the HTML template. If I use $first_file then I just get the file name without the date even though the uploaded file has the date attached at the beginning like it should. What can I place in my HTML template or my form with a hidden field to make the renamed file name show in the template?

  2. #2
    Join Date
    Dec 2003
    Posts
    3,907

    Thumbs up Re: file_names and template question

    Hi,

    When you use "file_names" to rename files, FormMail creates a new field to hold the new name of the file. The new field is the original field name prefixed with "name_of".

    So, if you rename "first_file", then in your templates $first_file evaluates to the original name of the file (that the user uploaded) and $name_of_first_file evaluates to the new name of the file.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Jul 2007
    Posts
    4

    Default Re: file_names and template question

    Yep. That did it. I'm sure I'll have some more questions in a while but even if I don't, it was $39 dollars well spent. Thanks for the quick response.

  4. #4
    Join Date
    Jan 2009
    Posts
    36

    Default Re: file_names and template question

    does this example actually RENAME the actual REAL UPLOADED file?

    there must be a way to rename the actual uploaded file to EXCLUDE the illegal characters...or what I would like to be illegal...like Spaces; /, non-alpha-number characters.

    I do this in a cgi script elsewhere...surely there is a way in formmail

  5. #5
    Join Date
    Dec 2003
    Posts
    3,907

    Default Re: file_names and template question

    Hi,

    Quote Originally Posted by dmac View Post
    does this example actually RENAME the actual REAL UPLOADED file?

    there must be a way to rename the actual uploaded file to EXCLUDE the illegal characters...or what I would like to be illegal...like Spaces; /, non-alpha-number characters.

    I do this in a cgi script elsewhere...surely there is a way in formmail
    It's not as straightforward as it seems.

    When PHP accepts an uploaded file, it saves the file on the server in a temporary directory (folder) with a perfectly valid and randomly generated name.

    For example, if I use your form to upload "My Bad %$@? file name.pdf", PHP accepts the file and saves it as, say "/tmp/A6IM9F.tmp".

    FormMail then has two pieces of information to work with:
    1. The actual file name (and its contents) saved on the server ("/tmp/A6IM9F.tmp").
    2. The original name of the file on the user's computer.
    When FormMail attaches the file to the email it sends you, it attaches the contents by reading the saved temporary file and puts the original file name in the email header (so your email program knows what the file was and is to be named).

    This use of the original name of the file may or may not be valid for your PC. If you have a Windows PC, then certain characters may be problem. If you have Mac or Linux PC, then certain other characters may be a problem.

    In other words, there's no universal set of "illegal characters".

    If you're saving the file on your server, using FormMail's FILE_REPOSITORY feature, the base file name will be used. So if there are any "/" or "\" (for a Windows server) characters in the uploaded file name only the last component will be used.

    It's still possible there are illegal characters in the file name after that and the server may then refuse to save the file - the uploading user will get an error.

    These problems are what FormMail's "file_names" renaming feature is there to solve.

    When you're attaching the uploaded file to an email, the "file_names" feature simply renames the file as it appears as an attachment in the email. So if, as an uploader, I upload "fred.pdf", you might rename it to "file1.pdf" and that's what is in your received email.

    When you're saving to a repository, the "file_names" feature actually renames the file as stored on your server.

    This is how you get "safe" file names stored on your server.

    So, if you renamed the uploaded file as "file1.pdf", that's what it would be stored as in your server repository.

    Of course, if you use the same name for every upload, then that file will be constantly overwritten (or not, depending on the FILE_OVERWRITE setting in FormMail). And that's not much use to you.

    So, you would generally use %nextnum% or the user's name or date and time, etc., to generate a unique file name when you rename an uploaded file.

    When you use the "file_names" feature, the original name of the file (on the uploader's computer) is still available as the file field name ($fieldname in a template). The new name of the file is available as an automatically created field called "name_of_fieldname" ($name_of_fieldname in a template).

    When saving the file in a repository on the server, you can then provide a download link in the email you receive (provided, of course, the repository is accessible on the web).

    You generate the correct link using a fixed path and the generated field name.

    For example, in an HTML template I'd put this:
    HTML Code:
    Uploaded file: $filefield <br />
    Link to download: <a href="http://www.yourserver.com/repository/$name_of_filefield">$filefield</a>
    or similar.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Newbie question on open_basedir error
    By zenprofit in forum FormMail Subscription Support
    Replies: 14
    Last Post: 14-Feb-2005, 10:35 PM
  2. question about PHP version 4.3.8
    By djgotee in forum FormMail Subscription Support
    Replies: 4
    Last Post: 29-Nov-2004, 12:46 AM
  3. TARGET_EMAIL question
    By middleburyman in forum FormMail Subscription Support
    Replies: 1
    Last Post: 03-Sep-2004, 09:30 PM
  4. Uploading question
    By tray in forum FormMail Subscription Support
    Replies: 2
    Last Post: 11-Aug-2004, 10:31 PM
  5. at mangle / e-mail question
    By Ibis in forum FormMail Subscription Support
    Replies: 3
    Last Post: 25-Feb-2004, 03:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts