コード例 #1
0
ファイル: Attachment.php プロジェクト: nidzix/Newscoop
 /**
  * This function should be called when an attachment is uploaded.  It will
  * save the attachment to the appropriate place on the disk, and create a
  * database entry for the file.
  *
  * @param array $p_fileVar
  *     <pre>
  * 		The variable from the $_FILES array.  The array specifies the following:
  *		$a["name"] = original name of the file.
  * 		$a["type"] = the MIME type of the file
  *		$a["tmp_name"] = the temporary storage location on disk of the file
  *		$a["size"] = size of the file, in bytes (not required)
  *		$a["error"] = 0 (zero) if there was no error
  *     </pre>
  *
  * @param array $p_attributes
  *		Optional attributes which are stored in the database.
  *		Indexes can be the following: 'content_disposition', 'fk_language_id', 'http_charset', 'fk_user_id'
  *
  * @param int $p_id
  *		If the attachment already exists and we just want to update it, specify the
  *		current ID here.
  *
  * @param bool $p_uploaded
  *      If the attachment was uploaded with other mechanism (ex: plUploader)
  *      this is set so that the single upload file from article functionality is still secured.
  *
  * @return mixed
  *		The Attachment object that was created or updated.
  *		Return a PEAR_Error on failure.
  */
 public static function OnFileUpload($p_fileVar, $p_attributes, $p_id = null, $p_uploaded = false)
 {
     if (!is_array($p_fileVar)) {
         return null;
     }
     // Verify its a valid file.
     $filesize = filesize($p_fileVar['tmp_name']);
     if ($filesize === false) {
         return new PEAR_Error("Attachment::OnFileUpload(): invalid parameters received.");
     }
     // Are we updating or creating?
     if (!is_null($p_id)) {
         // Updating the attachment
         $attachment = new Attachment($p_id);
         $attachment->update($p_attributes);
         // Remove the old file because
         // the new file may have a different file extension.
         if (file_exists($attachment->getStorageLocation())) {
             unlink($attachment->getStorageLocation());
         }
     } else {
         // Creating the attachment
         $attachment = new Attachment();
         $attachment->create($p_attributes);
         $attachment->setProperty('time_created', 'NULL', true, true);
     }
     $attachment->setProperty('file_name', $p_fileVar['name'], false);
     $attachment->setProperty('mime_type', $p_fileVar['type'], false);
     $attachment->setProperty('size_in_bytes', $p_fileVar['size'], false);
     $extension = "";
     $fileParts = explode('.', $p_fileVar['name']);
     if (count($fileParts) > 1) {
         $extension = array_pop($fileParts);
         $attachment->setProperty('extension', $extension, false);
     }
     $target = $attachment->getStorageLocation();
     $attachment->makeDirectories();
     ob_start();
     var_dump(is_uploaded_file($p_fileVar['tmp_name']));
     $dump = ob_get_clean();
     /**
      * for security reason
      *  for file uploaded normal not with other mechanism (ex: plUploader)
      *  we still need the move_uploaded_file functionality
      */
     if (!$p_uploaded && !move_uploaded_file($p_fileVar['tmp_name'], $target)) {
         $attachment->delete();
         return new PEAR_Error(camp_get_error_message(CAMP_ERROR_CREATE_FILE, $target), CAMP_ERROR_CREATE_FILE);
     }
     // if the file was uploaded with other mechanism (ex: plUploader) use rename(move) functionality
     if ($p_uploaded && !rename($p_fileVar['tmp_name'], $target)) {
         $attachment->delete();
         return new PEAR_Error(camp_get_error_message(CAMP_ERROR_CREATE_FILE, $target), CAMP_ERROR_CREATE_FILE);
     }
     chmod($target, 0644);
     $attachment->commit();
     return $attachment;
 }
コード例 #2
0
 /**
  * Approve action
  */
 public function approveAction()
 {
     $this->getHelper('contextSwitch')->addActionContext('approve', 'json')->initContext();
     $parameters = $this->getRequest()->getParams();
     if ($parameters['type'] == 'image') {
         $image = new Image($parameters['id']);
         $image->update(array('Status' => 'approved'));
         $user_id = $image->getUploadingUserId();
         $user = $this->_helper->service('user')->find($user_id);
         $this->_helper->service->getService('dispatcher')->notify('image.approved', new GenericEvent($this, array('user' => $user)));
     }
     if ($parameters['type'] == 'document') {
         $document = new Attachment($parameters['id']);
         $document->update(array('Status' => 'approved'));
         $user_id = $document->getUploadingUserId();
         $user = $this->_helper->service('user')->find($user_id);
         $this->_helper->service->getService('dispatcher')->notify('document.approved', new GenericEvent($this, array('user' => $user)));
     }
 }
コード例 #3
0
ファイル: FileService.php プロジェクト: itillawarra/cmfive
 /**
  * Uploads multiple attachments at once (Using the Html::multiFileUpload function
  *
  *  Stores in /uploads/attachments/<ObjectTableName>/<year>/<month>/<day>/<attachId>/<filename>
  *
  * @param <string> $requestKey
  * @param <DbObject> $parentObject
  * @param <Array> $titles
  * @param <Array> $descriptions
  * @param <Array> $type_codes
  * @return <bool> if upload was successful
  */
 function uploadMultiAttachment($requestkey, $parentObject, $titles = null, $descriptions = null, $type_codes = null)
 {
     if (!is_a($parentObject, "DbObject")) {
         $this->w->error("Parent object not found.");
         return false;
     }
     $rpl_nil = array("..", "'", '"', ",", "\\", "/");
     $rpl_ws = array(" ", "&", "+", "\$", "?", "|", "%", "@", "#", "(", ")", "{", "}", "[", "]", ",", ";", ":");
     if (!empty($_FILES[$requestkey]['name']) && is_array($_FILES[$requestkey]['name'])) {
         $file_index = 0;
         foreach ($_FILES[$requestkey]['name'] as $FILE_filename) {
             // Files can be empty
             if (!empty($FILE_filename['file'])) {
                 $filename = str_replace($rpl_ws, "_", str_replace($rpl_nil, "", basename($FILE_filename['file'])));
                 $att = new Attachment($this->w);
                 $att->filename = $filename;
                 $att->fullpath = null;
                 $att->parent_table = $parentObject->getDbTableName();
                 $att->parent_id = $parentObject->id;
                 $att->title = !empty($titles[$file_index]) ? $titles[$file_index] : '';
                 $att->description = !empty($descriptions[$file_index]) ? $descriptions[$file_index] : '';
                 $att->type_code = !empty($type_codes) ? $type_codes[$file_index] : '';
                 $att->insert();
                 $filesystemPath = FILE_ROOT . "attachments/" . $parentObject->getDbTableName() . '/' . date('Y/m/d') . '/' . $att->id . '/';
                 $filesystem = $this->getFilesystem($filesystemPath);
                 $file = new File($filename, $filesystem);
                 $file->setContent(file_get_contents($_FILES[$requestkey]['tmp_name'][$file_index]['file']));
                 $att->fullpath = str_replace(FILE_ROOT, "", $filesystemPath . $filename);
                 $att->update();
             }
             $file_index++;
         }
     }
     return true;
 }
コード例 #4
0
 /**
  * generateZip
  * 
  * @param AutoZipConfig $autozip
  * @param string $version_number
  */
 public static function generateZip(AutoZipConfig $autozip, $version_number = null)
 {
     // Move the configured folder as source folder
     if ($autozip->source_folder) {
         self::cliExec('mv download/' . $autozip->source_folder . ' source');
     } else {
         self::cliExec('mv download source');
     }
     // Zip with or without root folder in the zip
     if ($autozip->zip_folder) {
         self::cliExec('mv source ' . $autozip->zip_folder);
         self::cliExec('zip -qr autozip.zip ' . $autozip->zip_folder);
     } else {
         self::cliExec('zip -qr ../autozip.zip . ', array(), _AUTOZIP_TMP_ . 'source');
     }
     if ($autozip->id_attachment) {
         // get the Attachement config
         $attachment = new Attachment($autozip->id_attachment);
         if (!$attachment->file) {
             throw new PrestaShopException('The Attachement does not exists. Please update the autozip association');
         }
         // Move the generated zip as the "regular" Attachement
         self::cliExec('mv autozip.zip ' . _PS_DOWNLOAD_DIR_ . $attachment->file);
         if ($autozip->zip_basename) {
             $attachment->file_name = $autozip->zip_basename . ($version_number ? '-' . $version_number : '') . '.zip';
         }
         $attachment->mime = 'application/zip';
         $attachment->update();
     } else {
         if ($autozip->id_product_download) {
             // get the Product Download config
             $product_download = new ProductDownload($autozip->id_product_download);
             if (!$product_download->id_product) {
                 throw new PrestaShopException('The product Download does not exists. Please update the autozip association');
             }
             // Move the generated zip as the "regular" Product Download
             self::cliExec('mv autozip.zip ' . _PS_DOWNLOAD_DIR_ . $product_download->filename);
             if ($autozip->zip_basename) {
                 $product_download->display_filename = $autozip->zip_basename . ($version_number ? '-' . $version_number : '') . '.zip';
             }
             $product_download->date_add = date('Y-m-d H:i:s');
             //Prestashop dos not like the way he is himself storing an empty date (we do not change this field)
             if ($product_download->date_expiration === '0000-00-00 00:00:00') {
                 $product_download->date_expiration = null;
             }
             $product_download->update();
         }
     }
 }
コード例 #5
0
require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleAttachment.php');
require_once($GLOBALS['g_campsiteDir'].'/classes/Translation.php');

if (!SecurityToken::isValid()) {
    camp_html_display_error(getGS('Invalid security token!'));
    exit;
}
$f_language_id = Input::Get('f_language_id', 'int', 0);
$f_language_selected = Input::Get('f_language_selected', 'int', 0);

foreach ($_POST['file'] as $id => $values) {
    $description = new Translation((int) $f_language_selected);
    $description->create($values['f_description']); //$values

    $updateArray = array();
    $updateArray['fk_description_id'] = $description->getPhraseId();
/*    if ($values['f_language_specific'] == "yes") {
        $updateArray['fk_language_id'] = $f_language_selected;
    }
*/
    if ($values['f_content_disposition'] == "attachment") {
        $updateArray['content_disposition'] = "attachment";
    }
    $fileObj = new Attachment((int) $id);
    $fileObj->update($updateArray);
}

camp_html_add_msg(getGS("Images updated."), "ok");
camp_html_goto_page("/$ADMIN/media-archive/index.php#files");
?>