| |
|
Who's Online |
|
We have 26 guests online |
|
Newsletter |
|
Subscribe to our newsletter.
|
|
Donate |
If you use and like my scripts, and would like further developments, please consider donating a few bucks.
|
|
Hack for attaching documents to submission (1 viewing) (1) Guest
Favoured: 0
|
|
|
TOPIC: Hack for attaching documents to submission
|
Jurie (User)
Fresh Boarder
Posts: 7
|
|
Re:Hack for attaching documents to submission 3 Years, 3 Months ago
|
Karma: 0
|
Thank you .. can't wait 
|
|
|
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hack for attaching documents to submission 3 Years ago
|
Karma: 0
|
|
This is actually working for me pretty good. Upon inspection of the code, I'm not sure if it's particularly the most "secure" approach (no checks for file type, and size, etc), but I serves my needs right now.
One thing that I'm hoping to tweak is the validation before form submittal (right now this code allows an empty form to be submitted). I'm not sure where I need to add the validation code since this is linked through the .tmpl part of jobline.
Any pointers are appreciated. Thanks!
-Matt
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
godwin (Moderator)
Moderator
Posts: 60
|
|
Re:Hack for attaching documents to submission 3 Years ago
|
Karma: 2
|
Its only basic code for attachment. No other validations are added here.
for allowing only certain files to be uploaded you can use the add this code to the existing code
| Code: |
$allowedfiles = array("application/msword","text/richtext"«»);
if ( !in_array( $type, $allowedfiles ) )
{
mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=error&msg="._AD_INVALIDFILE );
return;
}
|
The code for attachmnet work both with and woithout attachment.
AND
If you intend to add some javascript validation, you could add it on 'jobline.html.php' in function 'function showApplicationForm' just above the lines
| Code: |
$tmpl = new mxTemplate( "$mosConfig_absolute_path/components/$option/templates/{$cfgjl['template']}" );
if ( $tmpl->setTemplate( "applicationform" ) )
|
Thanx  <br><br>Post edited by: godwin, at: 2007/02/19 12:47
|
|
|
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hack for attaching documents to submission 3 Years ago
|
Karma: 0
|
admin wrote:
QUOTE: Attachment to the application form will be in v1.2, but not in this form, it will use a more stable functionality that hopefully should work for everyone.
When will that RC be out?
|
|
|
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hack for attaching documents to submission 3 Years ago
|
Karma: 0
|
|
I copied all of the parts to the specific files, and got this when i click on apply:
Warning: constant() [function.constant]: Couldn't find constant _JL_ATTACH_RESUME in /home/mbower/public_html/jobsnew/components/com_jobline/mxtemplate.php(124) : regexp code on line 1
anyone got any ideas?
many thanks
j
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hack for attaching documents to submission 3 Years ago
|
Karma: 0
|
mbowerbank wrote:
QUOTE: I copied all of the parts to the specific files, and got this when i click on apply:
Warning: constant() [function.constant]: Couldn't find constant _JL_ATTACH_RESUME in /home/mbower/public_html/jobsnew/components/com_jobline/mxtemplate.php(124) : regexp code on line 1
anyone got any ideas?
many thanks
j
Sorry im a complete idiot, and figured that i hadnt added this text in the com_jobline/languages/english.php
DEFINE('_JL_ATTACH_RESUME', 'Attach Resume'  ;
anyone whos as stupid as me just copy and paste this into the english.php file
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
olle (Admin)
Admin
Posts: 1031
|
|
Re:Hack for attaching documents to submission 3 Years ago
|
Karma: 17
|
|
Good tip, this also works if a similar error occurs when using any other language file than English, since some strings might be missing in those.
It really should be a more clear error message, but since I'm planning on switching template system in the future I don't want to work so much on the current one.
|
|
|
|
|
|
|
Olle Johansson
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hack for attaching documents to submission 2 Years, 11 Months ago
|
Karma: 0
|
Hello
I had this thing working today, briefly, but stupidly forgot to take a spare copy of everything before I started making other changes.
Now, everything is back to the way it was before - that is, the attachment comes integrated into the e-mail; not as a picture/file, but as garbled text.
Anyone familiar with that problem?
Here is the code in jobline.php
| Code: |
function sendApplication( $id )
{
global $database, $mosConfig_absolute_path, $mosConfig_live_site, $option, $cfgjl, $mainframe, $my, $Itemid;
$row = new mosJobPosting( $database );
$row->load( $id );
if ( !$row->id )
{
mosRedirect( "$mosConfig_live_site/index.php?option=$option&task=error&msg=" . _JL_NOSUCHJOB );
}
else
{
$tmplvars = get_object_vars( $row );
foreach ( $_REQUEST as $k => $v )
{
$tmplvars["req_$k"] = $v;
}
$reply_email = $tmplvars["req_email"];
$tmpl = new mxTemplate( "$mosConfig_absolute_path/components/com_jobline/templates/{$cfgjl['template']}" );
if ( $tmpl->setTemplate( "applicationemail" ) )
{
// store the file information to variables for easier access
$tmp_name= $_FILES['attach']['tmp_name'];
$type = $_FILES['attach']['type'];
$name = $_FILES['attach']['name'];
$size = $_FILES['attach']['size'];
$error = $_FILES['attach']['error'];
$message = '';
$mime_boundary = '';
$tmpl->setVars( $tmplvars );
$tmpl->parseTemplate();
$message = $tmpl->getOutput();
// if the upload succeded, the file will exist
if ( file_exists($tmp_name) )
{
// generate a random string to be used as the boundary marker
$mime_boundary = "<<<--==Multipart_Boundary_x".md5(mt_rand())."x";
// check to make sure that it is an uploaded file and not a system file
if( is_uploaded_file($tmp_name) )
{
$message .= "\n\n Attachment : $name";
// open the file for a binary read
$file = fopen( $tmp_name,'rb' );
// read the file content into a variable
$data = fread( $file,filesize($tmp_name) );
// close the file
fclose( $file );
// now we encode it and split it into acceptable length lines
$data = chunk_split( base64_encode($data) );
}
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
if( $data )
{
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$name}\"\n" .
"Content-Transfer-Encoding: base64 \n\n" . $data . "\n\n";
}
$message .= "--{$mime_boundary}--\n";
}
$Replyto = $reply_email;
//function sendEmail( $email, $subject, $message, $fromname, $fromemail, $replyto, $mime_boundary )
sendEmail( $row->contactemail, _JL_APPLICATION_SUBJECT, $message, $cfgjl['mailfromname'], $Replyto, $Replyto, $mime_boundary);
mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=thankyou&id=$id" );
}
else
{
showError( _JL_ERRORSETTMPL . ": applicationemail" );
}
}
}
|
And here is the code in jobline.common.php
| Code: |
function sendEmail( $email, $subject, $message, $fromname='', $fromemail='', $replyto='', $mime_boundary='' )
{
$headers = "";
if ( trim( $fromemail ) )
{
$headers = "From: $fromname <$fromemail>\r\n";
}
if ( trim( $replyto ) )
{
$headers .= "Reply-To: <$replyto>\r\n";
}
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Low\r\n";
$headers .= "X-Mailer: Joomla Open Source 1.12\r\n";
if( $mime_boundary )
{
$headers .= "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
}
@mail($email, $subject, $message, $headers);
}
|
In the template, I have:
| Code: |
<form action="index2.php" method="POST" name="adminForm" enctype="multipart/form-data">
and where the input box is...
<input type="file" name="attach" class="inputbox2" size="60" value="">
|
Any help would be greatly appreciated 
Thank you for an excellent component.
Below is the attachment code as seen in a typical application - not attached, but integrated into the e-mail:
| Code: |
Attachment : ONLINE.BMP
--<<<--==Multipart_Boundary_x77e5853ac728d175fe4cb854e452db9fx
Content-Type: image/bmp;
name="ONLINE.BMP"
Content-Disposition: attachment;
filename="ONLINE.BMP"
Content-Transfer-Encoding: base64
Qk12AgAAAAAAAHYAAAAoAAAAIAAAACAAAAABAAQAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAMDAwACAgIAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA
////AGZmZmZu7u7u7uZmZmZmZmZmZmZu5mqqqqpu7uZmZmZmZmZu5mqmZmZmqqZu5mZmZmZm5mqm
ZgAAAAZqpm5mZmZmbmamZgD//39wBmpm5mZmZm5qZgD///f/fuAGpm5mZmbmpmD////3937u4Gpm
5mZm5qYHf///9/d+7u4GpuZmbmpgd3f///f3fu7u4GpmZm5qYKd3f//3937u53BqZmZmagqnd3f/
9/d+7nf/BqZmZqYKqnd3f/f3fud/9wamZmpgqqqnd3f3935393dwpmZqYKqqqnd3AAB+/3e3cKZm
amCqqqp3cGZmD3d3u3CmZmpgqqqqp3BmZgd+53dwpmZqYLuqqqpwZmZgfud2YGZmamC7u7qqoGZm
YAYAYGBmZmpgu7u7u7sGZma7Zm7mZmZmpgu7u7u3cAAGu2puZmZmZqYLu7u7d3d3BmaqZmZmZmZm
YLu7t3d3cGZ3ZmZmZmZmZmC7u7d3d3BmdmbuZmZmZmZmC7t3d3cGZmZm7mZmZmZmZmC3d3dwZmaq
ZmZmZmZmZmZmAHd3BmZmqmd2ZmZmZmZmZmYAcGZmZmZmdmZmZmZmaZZpZpZplpaWaWmZZmZmZpZp
aWaWaWaWlmlpZmZmZmaWaWlmmZlmlpZpaZZmZmZmlmlpZpZpZmaWaWlmZmZmZmmWaZlmaWaWmZZp
mWZm
--<<<--==Multipart_Boundary_x77e5853ac728d175fe4cb854e452db9fx--
|
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
olle (Admin)
Admin
Posts: 1031
|
|
Re:Hack for attaching documents to submission 2 Years, 11 Months ago
|
Karma: 17
|
|
The most common cause of this problem is malformed headers, the mail isn't properly formatted.
I can't tell you exactly what's wrong, but a quick look reveals that you are using different ways to mark new lines. You should try to replace all "\n" into "\r\n" unless they are already preceded by "\r".
A better way would be to use an API for formatting mails with attachments to make sure they are properly formatted. The Joomla API includes such a function, so it would probably be easier to just look it up in the Joomla developer documentation.
|
|
|
|
|
|
|
Olle Johansson
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Hack for attaching documents to submission 2 Years, 11 Months ago
|
Karma: 0
|
Not only a fast reply, but the perfect one
You hit the nail on the head(er), everything working fine now.
I will look into the API as well, did not know about that possibility.
Thank you very much for the assistance Ollie.
Best wishes,
Baldur
Just for those who will follow, here is the code as it works for me.
1. The function sendApplication( $id ) in jobline.php:
| Code: |
function sendApplication( $id )
{
global $database, $mosConfig_absolute_path, $mosConfig_live_site, $option, $cfgjl, $mainframe, $my, $Itemid;
$row = new mosJobPosting( $database );
$row->load( $id );
if ( !$row->id )
{
mosRedirect( "$mosConfig_live_site/index.php?option=$option&task=error&msg=" . _JL_NOSUCHJOB );
}
else
{
$tmplvars = get_object_vars( $row );
foreach ( $_REQUEST as $k => $v )
{
$tmplvars["req_$k"] = $v;
}
$reply_email = $tmplvars["req_email"];
$tmpl = new mxTemplate( "$mosConfig_absolute_path/components/com_jobline/templates/{$cfgjl['template']}" );
if ( $tmpl->setTemplate( "applicationemail" ) )
{
// store the file information to variables for easier access
$tmp_name= $_FILES['attach']['tmp_name'];
$type = $_FILES['attach']['type'];
$name = $_FILES['attach']['name'];
$size = $_FILES['attach']['size'];
$error = $_FILES['attach']['error'];
$message = '';
$mime_boundary = '';
$tmpl->setVars( $tmplvars );
$tmpl->parseTemplate();
$message = $tmpl->getOutput();
// if the upload succeded, the file will exist
if ( file_exists($tmp_name) )
{
// generate a random string to be used as the boundary marker
$mime_boundary = "<<<--==Multipart_Boundary_x".md5(mt_rand())."x";
// check to make sure that it is an uploaded file and not a system file
if( is_uploaded_file($tmp_name) )
{
$message .= "\r\n\r\n Attachment : $name";
// open the file for a binary read
$file = fopen( $tmp_name,'rb' );
// read the file content into a variable
$data = fread( $file,filesize($tmp_name) );
// close the file
fclose( $file );
// now we encode it and split it into acceptable length lines
$data = chunk_split( base64_encode($data) );
}
// next, we'll build the message body
// note that we insert two dashes in front of the
// MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content and set another boundary to
// indicate that the end of the file has been reached
if( $data )
{
$message .= "--{$mime_boundary}\r\n" .
"Content-Type: {$type};\r\n" .
" name=\"{$name}\"\r\n" .
"Content-Disposition: attachment;\r\n" .
" filename=\"{$name}\"\r\n" .
"Content-Transfer-Encoding: base64 \r\n\r\n" . $data . "\r\n\r\n";
}
$message .= "--{$mime_boundary}--\r\n";
}
$Replyto = $reply_email;
//function sendEmail( $email, $subject, $message, $fromname, $fromemail, $replyto, $mime_boundary )
sendEmail( $row->contactemail, _JL_APPLICATION_SUBJECT, $message, $cfgjl['mailfromname'], $Replyto, $Replyto, $mime_boundary);
mosRedirect( "$mosConfig_live_site/index.php?option=$option&Itemid=$Itemid&task=thankyou&id=$id" );
}
else
{
showError( _JL_ERRORSETTMPL . ": applicationemail" );
}
}
}
|
2. The function sendEmail in jobline.common.php:
| Code: |
function sendEmail( $email, $subject, $message, $fromname='', $fromemail='', $replyto='', $mime_boundary='' )
{
$headers = "";
if ( trim( $fromemail ) )
{
$headers = "From: $fromname <$fromemail>\r\n";
}
if ( trim( $replyto ) )
{
$headers .= "Reply-To: <$replyto>\r\n";
}
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Low\r\n";
$headers .= "X-Mailer: Joomla Open Source 1.12\r\n";
if( $mime_boundary )
{
$headers .= "MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
}
@mail($email, $subject, $message, $headers);
}
|
The applicationform.tmpl needs to have some simple changes as well, which can be seen in previous posts.
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
|
|
|
|
|
|
|