Forums

uploaded file name

density5 05 Feb, 2010
Hi all,

I have confused myself with the $attachments['field_name'] I am trying to get the url and file name info in an email to automate posting some images.

My Form Code


<div class="form_item">
<div class="form_element cf_fileupload">
<label class="cf_label" style="width: 150px;">Photo 1</label>
<input class="cf_fileinput cf_inputbox" title="file_1" size="20" id="file_1" name="file_1" type="file" />
<a class="tooltiplink" onclick="return false;">
<img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
<div class="tooltipdiv">Photo 1 :: We accept JPG/GIF/PNG and BMP Image type files only. We will resize the photos for you.</div>
</div>
<div class="cfclear"> </div>
</div>


My Email Template Code


<div class="form_item">
<div class="form_element cf_textarea">
<label class="cf_label" style="width: 150px;">Photo 1 Url Link: </label>http://mywebsite.com/images/carssales/<?php echo basename($attachments['file_1']);?>
</div>
</div>

But I cant get the image name to echo - I have also tried {file_1} and in both I get a blank after the url.

Any ideas guys?
GreyHead 07 Feb, 2010
Hi density5,

You can use this code in the OnSubmit Before box. Mostly it switched form a path to a URL:
<?php
// get the form uploads information
$MyUploads =& CFUploads::getInstance($MyForm->formrow->id);
// extract the file path
$file_path = $MyUploads->attachments[file_1];
// remove the 'root folder' from the beginning
$file_url = substr($file_path, strlen(JPATH_SITE)+1);
//correct any mis-directed separators
$file_url = str_replace(DS, '/', $file_url);
// add the domain name to the beginning
$file_url = JURI::base().$file_url;
// save the URL into the form results
JRequest::setVar('file_url', $file_url);
?>
and then add {file_url} in the Email Template.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger