$ajaxuploadFieldname = $modx->getOption('ajaxuploadFieldname', $scriptProperties, '');
$ajaxuploadFieldformat = $modx->getOption('ajaxuploadFieldformat', $scriptProperties, 'csv');
if ($ajaxuploadFieldname) {
$attach = $hook->getValue($ajaxuploadFieldname);
if ($ajaxuploadFieldformat == 'json') {
$attach = json_decode($attach);
} else {
$attach = explode(',', $attach);
}
$hook->modx->getService('mail', 'mail.modPHPMailer');
$count = count($attach);
for($i=0; $i < $count; $i++)
{
$hook->modx->mail->mailer->AddAttachment(substr($attach[$i],1)); //remove the first slash!
//$modx->log(modX::LOG_LEVEL_ERROR,'attach files: '.substr($attach[$i],1));
}
}
return true;
<?php
$ajaxuploadFieldname = $modx->getOption('ajaxuploadFieldname', $scriptProperties, '');
$ajaxuploadFieldformat = $modx->getOption('ajaxuploadFieldformat', $scriptProperties, 'csv');
$basepath = $modx->getOption('base_path');
if ($ajaxuploadFieldname) {
$attach = $hook->getValue($ajaxuploadFieldname);
if ($ajaxuploadFieldformat == 'json') {
$attach = json_decode($attach);
} else {
$attach = explode(',', $attach);
}
$hook->modx->getService('mail', 'mail.modPHPMailer');
foreach ($attach as $value) {
$value = substr($value,1); //remove the first slash!
$hook->modx->mail->mailer->AddAttachment($basepath.$value);
//$modx->log(modX::LOG_LEVEL_ERROR,'attach files: '.$value);
}
}
return true;
and why do you remove the first slash (there is none in a filename only) and don't use the full path on the server?
<?php
$ajaxuploadFieldname = $modx->getOption('ajaxuploadFieldname', $scriptProperties, '');
$ajaxuploadFieldformat = $modx->getOption('ajaxuploadFieldformat', $scriptProperties, 'csv');
$assetsPath = $modx->getOption('assets_path');
$assetsUrl = $modx->getOption('assets_url');
$assetsUrlLength = strlen($assetsUrl);
if ($ajaxuploadFieldname) {
$attachments = $hook->getValue($ajaxuploadFieldname);
if ($ajaxuploadFieldformat == 'json') {
$attachments = json_decode($attachments);
} else {
$attachments = explode(',', $attachments);
}
$hook->modx->getService('mail', 'mail.modPHPMailer');
foreach ($attachments as $attachment) {
$attachment = substr($attachment, $assetsUrlLength);
$hook->modx->mail->mailer->AddAttachment($assetsPath . $attachment);
}
}
return true;return $ajaxUpload->output() . $ajaxUpload->debugOutput();
Could it be that you call FormIt with &debug=`1`?No. Don`t use any debug settings.
[[!FormIt? &preHooks=`Formit2AjaxUpload` &hooks=`AjaxUpload2Formit,email` &ajaxuploadFieldname=`image` &ajaxuploadTarget=`images/user/` &ajaxuploadUid=`image` &emailTpl=`AnketaTpl` &emailSubject=`Копия Вашей анкеты` &emailFrom=`[email protected]` &emailTo=`[[+email]]` &validate=`email:email:required, fio:required, tel:required, vuz:required, gofrom:required, formob:required, gofrom:required, spec:required, disc:required, gomonth:required, isotch:required, isplan:required, sfera:required` ]]
[[!AjaxUpload?
&uid=`image`
&allowedExtensions=`jpg,jpeg,png,gif,doc,docx,xls,xlsx,zip,arj`
&thumbX=`75`
&thumbY=`75`
&maxFiles=`5`
]]
$this->config = array_merge($this->config, array(
'debug' => false,
'uid' => $this->modx->getOption('uid', $config, md5($this->modx->getOption('site_url') . '-' . $resourceId), true),
'uploadAction' => $assetsUrl . 'connector.php',
'newFilePermissions' => '0664',
'filecopierPath' => '', // not implemented yet
));