Exemplo n.º 1
0
 public function addAttachments()
 {
     if (!is_dir($this->settings->attachpathfaq) || !is_writeable($this->settings->attachpathfaq)) {
         die('FAQ attachments folder (<b>' . $this->settings->attachpathfaq . '</b>) doesn`t exist or is not writeable. Please check this folder exists and has write permissions.');
     }
     $count = 0;
     for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) {
         $display = $_POST['name'][$i];
         $remote = $_POST['remote'][$i];
         $f_name = $_FILES['file']['name'][$i];
         $f_temp = $_FILES['file']['tmp_name'][$i];
         $f_mime = $_FILES['file']['type'][$i];
         $f_size = $f_name && $f_temp ? $_FILES['file']['size'][$i] : ($remote ? faqCentre::remoteSize($remote) : '0');
         $ext = substr(strrchr(strtolower($f_name), '.'), 1);
         $new = '';
         // Add to database..
         mysql_query("INSERT INTO `" . DB_PREFIX . "faqattach` (\n    `ts`,\n    `name`,\n    `remote`,\n    `path`,\n    `size`,\n\t`mimeType`\n    ) VALUES (\n    UNIX_TIMESTAMP(UTC_TIMESTAMP),\n    '" . mswSafeImportString($display) . "',\n    '" . mswSafeImportString($remote) . "',\n    '" . mswSafeImportString($f_name) . "',\n    '{$f_size}',\n\t'{$f_mime}'\n    )") or die(mswMysqlErrMsg(mysql_errno(), mysql_error(), __LINE__, __FILE__));
         $ID = mysql_insert_id();
         // Now upload file if applicable..
         if ($ID > 0) {
             if ($remote == '' && $f_size > 0 && is_uploaded_file($f_temp)) {
                 // Does file exist?
                 if (file_exists($this->settings->attachpathfaq . '/' . $f_name)) {
                     // Are we renaming attachments..
                     if ($this->settings->renamefaq == 'yes') {
                         $new = $ID . '-' . time() . '.' . $ext;
                     } else {
                         $new = $ID . '_' . mswCleanFile($f_name);
                     }
                     move_uploaded_file($f_temp, $this->settings->attachpathfaq . '/' . $new);
                     // Required by some servers to make image viewable and accessible via FTP..
                     @chmod($this->settings->attachpathfaq . '/' . $new, $this->internal['chmod-after']);
                 } else {
                     // Are we renaming attachments..
                     if ($this->settings->renamefaq == 'yes') {
                         $new = $ID . '.' . $ext;
                     } else {
                         $new = mswCleanFile($f_name);
                     }
                     move_uploaded_file($f_temp, $this->settings->attachpathfaq . '/' . $new);
                     // Required by some servers to make image viewable and accessible via FTP..
                     @chmod($this->settings->attachpathfaq . '/' . $new, $this->internal['chmod-after']);
                 }
             }
             // Was file renamed?
             mysql_query("UPDATE `" . DB_PREFIX . "faqattach` SET `path` = '{$new}' WHERE `id` = '{$ID}'");
             ++$count;
         }
         // Remove temp file if it still exists..
         if (file_exists($f_temp)) {
             @unlink($f_temp);
         }
     }
     // Rebuild sequence..
     faqCentre::rebuildAttSequence();
     return $count;
 }