예제 #1
0
function truncateFilename($filename, $length)
{
    $extension = substr(strrchr($filename, '.'), 1);
    $filename = myoc_basename($filename, '.' . $extension);
    if (strlen($filename) > $length) {
        return substr($filename, 0, $length) . '...' . $extension;
    }
    return $filename . '.' . $extension;
}
예제 #2
0
 public function download()
 {
     if (method_exists($this->encryption, 'encrypt')) {
         $encryption = $this->encryption;
     } else {
         $this->load->library('encryption');
         $encryption = new Encryption($this->config->get('config_encryption'));
     }
     $filename = $encryption->decrypt($this->request->get['f']);
     $mask = myoc_basename(substr($filename, 0, strrpos($filename, '.')));
     if (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident')) {
         $mask = urlencode($mask);
     }
     if (file_exists(DIR_UPLOAD . $filename)) {
         if (!headers_sent()) {
             header('Content-Type: application/octet-stream');
             header('Content-Description: File Transfer');
             header('Content-Disposition: attachment; filename="' . $mask . '"');
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
             header('Content-Length: ' . filesize(DIR_UPLOAD . $filename));
             readfile(DIR_UPLOAD . $filename, 'rb');
             exit;
         } else {
             exit('Error: Headers already sent out!');
         }
     } else {
         exit('Error: Could not find file ' . DIR_UPLOAD . $filename . '!');
     }
 }
예제 #3
0
 public function addUpload($data)
 {
     $this->load->language('myoc/copu');
     $mask = myoc_basename(substr($data['filename'], 0, strrpos($data['filename'], '.')));
     //$this->db->query("INSERT INTO " . DB_PREFIX . "myoc_upload SET filename = '" . $this->db->escape($data['filename']) . "', mask = '" . $this->db->escape($mask) . "', date_added = NOW();");
     //$upload_id = $this->db->getLastId();
     $upload_id = $data['upload_id'];
     $email_attachment = false;
     if (isset($data['customer_id'])) {
         $this->db->query("INSERT INTO " . DB_PREFIX . "myoc_customer_upload SET customer_id = '" . (int) $data['customer_id'] . "', upload_id = '" . (int) $upload_id . "';");
         if ($this->config->get('copu_customer_email_alert')) {
             $this->load->model('account/customer');
             $customer_info = $this->model_account_customer->getCustomer($data['customer_id']);
             $subject = sprintf($this->language->get('text_new_upload_title'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $this->language->get('text_customer'), $customer_info['firstname'] . ' ' . $customer_info['lastname']);
             $text = sprintf($this->language->get('text_new_upload_body'), $this->language->get('text_customer'), $customer_info['firstname'] . ' ' . $customer_info['lastname'] . ' (' . $customer_info['email'] . ')') . "\n\n";
             if ($this->config->get('copu_customer_email_attachment')) {
                 $email_attachment = true;
             }
         }
     }
     if (isset($data['order_id'])) {
         $this->db->query("INSERT INTO " . DB_PREFIX . "myoc_order_upload SET order_id = '" . (int) $data['order_id'] . "', upload_id = '" . (int) $upload_id . "';");
         $order_info_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int) $data['order_id'] . "'");
         if ($this->config->get('copu_order_history_modify_email_alert') && $order_info_query->row['order_status_id']) {
             $subject = sprintf($this->language->get('text_new_upload_title'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $this->language->get('text_order'), $data['order_id']);
             $text = sprintf($this->language->get('text_new_upload_body'), $this->language->get('text_order'), $data['order_id']) . "\n\n";
             if ($this->config->get('copu_order_email_attachment')) {
                 $email_attachment = true;
             }
         }
     }
     if (isset($subject)) {
         $text .= sprintf($this->language->get('text_new_upload_file'), $mask) . "\n";
         $text .= sprintf($this->language->get('text_new_upload_date'), date($this->language->get('date_format_long') . ' ' . $this->language->get('time_format'))) . "\n";
         // Admin Alert Mail
         $mail = new Mail();
         $mail->protocol = $this->config->get('config_mail_protocol');
         $mail->parameter = $this->config->get('config_mail_parameter');
         $mail->hostname = $this->config->get('config_smtp_host');
         $mail->username = $this->config->get('config_smtp_username');
         $mail->password = $this->config->get('config_smtp_password');
         $mail->port = $this->config->get('config_smtp_port');
         $mail->timeout = $this->config->get('config_smtp_timeout');
         if ($email_attachment) {
             copy(DIR_UPLOAD . $data['filename'], DIR_UPLOAD . $mask);
             $mail->addAttachment(DIR_UPLOAD . $mask);
         }
         $mail->setTo($this->config->get('config_email'));
         $mail->setFrom($this->config->get('config_email'));
         $mail->setSender($this->config->get('config_name'));
         $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
         $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
         $mail->send();
         // Send to additional alert emails
         $emails = explode(',', $this->config->get('config_alert_emails'));
         foreach ($emails as $email) {
             if ($email && preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $email)) {
                 $mail->setTo($email);
                 $mail->send();
             }
         }
         if (file_exists(DIR_UPLOAD . $mask)) {
             unlink(DIR_UPLOAD . $mask);
         }
     }
     return $upload_id;
 }