Пример #1
0
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
     $imageUrl = clone \Env::get("Resolver")->getUrl();
     // get the image url
     $files = array();
     $directory = \Env::get('Resolver')->getCmd();
     if ($directory != 'Downloads') {
         $targetPath = $cx->getWebsiteMediaFileSharingPath() . '/' . (!empty($directory) ? $directory . '/' : '');
         $targetPathWeb = $cx->getWebsiteMediaFileSharingWebPath() . '/' . (!empty($directory) ? $directory . '/' : '');
     } else {
         $targetPath = $cx->getWebsiteImagesDownloadsPath() . '/';
         $targetPathWeb = $cx->getWebsiteImagesDownloadsWebPath() . '/';
     }
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     $dirTempPath = $tup[0] . '/' . $tup[2] . '/';
     //get the tmp/$uploadId files
     foreach (glob($dirTempPath . '/*') as $uploadedFile) {
         $file = basename($uploadedFile);
         $uploadedFileName = $fileSystem->copyFile($dirTempPath, $file, $targetPath, $file, false);
         if ($uploadedFileName === 'error') {
             continue;
         }
         \Cx\Lib\FileSystem\FileSystem::delete_file($dirTempPath . '/' . $file);
         $uploadedFileSource = $targetPathWeb . $uploadedFileName;
         $hash = self::createHash();
         $check = self::createCheck($hash);
         $objResult = $objDatabase->Execute("INSERT INTO " . DBPREFIX . "module_filesharing (`file`, `source`, `cmd`, `hash`, `check`, `upload_id`)\n                                VALUES (\n                                    '" . contrexx_raw2db($uploadedFileName) . "',\n                                    '" . contrexx_raw2db($uploadedFileSource) . "',\n                                    '" . contrexx_raw2db($directory) . "',\n                                    '" . contrexx_raw2db($hash) . "',\n                                    '" . contrexx_raw2db($check) . "',\n                                    '" . contrexx_input2int($uploadId) . "'\n                                )");
         if (!$objResult) {
             continue;
         }
         $imageUrl->setParam("act", "image");
         $imageUrl->setParam("hash", $hash);
         $info = pathinfo($cx->getWebsiteOffsetPath() . $uploadedFileSource, PATHINFO_EXTENSION);
         // if the file is an image show a thumbnail of the image
         if (!in_array(strtoupper($info), array('JPEG', 'JPG', 'TIFF', 'GIF', 'BMP', 'PNG'))) {
             $imageUrl = false;
         }
         $fieldId = $objDatabase->Insert_ID();
         $files[] = array("name" => $uploadedFileName, "image" => $imageUrl->toString(), "download" => parent::getDownloadLink($fieldId), "delete" => parent::getDeleteLink($fieldId));
     }
     return $files;
 }
Пример #2
0
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $files = array();
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     // loop through the uploaded files
     $objResult = $objDatabase->Execute("SELECT `id`, `file`, `source`, `hash`, `check` FROM " . DBPREFIX . "module_filesharing WHERE `upload_id` = " . intval($uploadId));
     if ($objResult !== false && $objResult->RecordCount() > 0) {
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         while (!$objResult->EOF) {
             $filePath = explode("/", $objResult->fields["source"]);
             $fileNameSource = end($filePath);
             $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
             $directory = \Env::get('Resolver')->getCmd();
             if ($directory != 'Downloads') {
                 $newPath = $cx->getWebsiteMediaFileSharingPath() . '/' . $directory . '/';
             } else {
                 $newPath = $cx->getWebsiteImagesDownloadsPath() . '/';
             }
             $fileSystem->copyFile($tup[0] . '/' . $tup[2] . '/', $fileNameSource, $newPath, $fileNameSource, false);
             // get file name
             $fileName = $objResult->fields["file"];
             // get the image url
             $imageUrl = clone \Env::get("Resolver")->getUrl();
             $imageUrl->setParam("act", "image");
             $imageUrl->setParam("hash", $objResult->fields["hash"]);
             $info = pathinfo($cx->getWebsiteOffsetPath() . $objResult->fields["source"]);
             // if the file is an image show a thumbnail of the image
             if (!in_array(strtolower($info["extension"]), array("jpeg", "jpg", "png", "gif"))) {
                 $imageUrl = false;
             }
             $files[] = array("name" => $fileName, "image" => $imageUrl, "download" => parent::getDownloadLink($objResult->fields["id"]), "delete" => parent::getDeleteLink($objResult->fields["id"]));
             $objResult->moveNext();
         }
     }
     return $files;
 }