有一个职业页面,我将在其中填充详细信息,并附上简历,并在用户填写数据后发送电子邮件,同时简历显示空白页面。
如果我们不添加上传简历选项,则工作正常。
var $image_path;
var $image_path_url;
function __construct()
{
parent::__construct();
$this->image_path =realpath(APPPATH . '..admin/images/blogimages');
$this->image_path_url = base_url().'admin/images/blogimages/thumbs';
}
function apply($email)
{
$name = $this->input->post('fullname');
$email = $this->input->post('email');
$phone = $this->input->post('mobilenumber');
if ( $_FILES AND $_FILES['image_path']['name'])
{
$file_name = $this->do_upload2();
if(is_array($file_name))
{
$error['imageerror'] = $file_name['error'];
}
else
$data['image_path']=$file_name;
}
if(!isset($data['image_path']) && !isset($error['imageerror']))
$error['imageerror'] ="Please Upload an image";
if(isset($error))return $error;
//set to_email id to which you want to receive mails
$to_email = '[email protected]';
$config=Array(
'protocol'=> 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
'smtp_port' => '465', //smtp port number
'smtp_user' => '[email protected]',
'smtp_pass' => 'PASSWORD123', //$from_email password
'mailtype' =>'html',
'newline' =>"\r\n",
'crlf' =>"\r\n",
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = array();
$message[] = 'Fullname : '.trim($name).' ';
$message[] = 'Email : '.trim($email).' ';
$message[] = 'Mobile : '.trim($phone).' ';
//$message = implode(PHP_EOL, $message);
$message = implode('<br>', $message);
//send mail
$this->load->library('email',$config);
$this->email->from($email);
$this->email->to($to_email);
//$list = array();
$path = set_realpath('admin/images/blogimages/thumbs');
$this->email->message($message);
$this->email->attach($path . 'image_path');
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
if ($this->email->send())
{
$this->flash->success('Thank you for applying to this post we will get back to you soon!</div>');
redirect('apply');
}
else
{
$this->flash->success('There is error in sending mail! Please try again later');
redirect('apply');
}
}
function do_upload2()
{
$config = array(
'allowed_types' => 'doc|docx|pdf',
'upload_path' => $this->image_path,
'max_size' => 20000,
'maintain_ratio'=>FALSE
);
$this->load->library('upload', $config);
if(!$this->upload->do_upload('image_path'))
{
return $error = array('error' => $this->upload->display_errors());
}
else
{
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' =>$this->image_path . '/thumbs',
'maintain_ratio' => FALSE,
'width' => 83,
'height' => 83
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$filename =time().preg_replace('/[^A-Za-z0-9\s.\s-]/', '_', $image_data['file_name']);
rename($image_data['full_path'],$image_data['file_path'].$filename);
rename($image_data['file_path'].'thumbs/'.$image_data['file_name'],$image_data['file_path'].'thumbs/'.$filename);
return $filename;
}
}
最佳答案
添加这些行以在发送电子邮件时上传图像和文件。
$config2 = array(
'upload_path'=>'../admin/images/blogimages',
'allowed_types' => 'pdf|doc|docx',
'max_size' => 20000,
);
$this->load->library('upload', $config2);
$this->upload->do_upload('attachment');
$upload_data = $this->upload->data();
$this->email->attach($upload_data['full_path']);