diff --git a/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc b/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc index 2d731dfb69f034d16fd84b0ba813e9778d88d607..d4366f20ecb28e896f8bc2cc1586eb4ce1a897f5 100755 --- a/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc +++ b/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc @@ -38,8 +38,8 @@ class File_downloader extends Vitis { * @param type $oConnection connection object */ function __construct($aPath, $aValues, $properties, $bShortcut = false, $oConnection = false) { - $this->aValues = $aValues; - $this->aProperties = $properties; + $this->aValues = $aValues; + $this->aProperties = $properties; } /** @@ -87,74 +87,74 @@ class File_downloader extends Vitis { $bReturnFile = true; // si un paramètre est manquant on coupe if ((!empty($this->aValues["key"])) && (!empty($this->aValues["eTag"]))){ - $sPath = ""; - if ($this->aProperties["filesystem"] == 's3'){ - $sPath = $this->aProperties['extract_dir'] . "/" . getUniqRandomId(); - // traitement du bucket et de ses sous-dossiers - $sBucket = $this->aProperties['fileS3UploaderBucket']; - $sPrefix = ""; - // Suppression du slash de début de ligne. - if (strpos($this->aValues["key"], '/') === 0) - $this->aValues["key"] = substr($this->aValues["key"], 1); - // - if (strpos($sBucket, "/") > -1){ - $aBucket = explode("/", $sBucket ); - $sBucket = $aBucket[0]; - $sPrefix = implode("/", array_slice($aBucket, 1)); - } - // Création du client S3 - $s3 = new Aws\S3\S3Client(array( - 'version'=>'latest', - 'region'=> $this->aProperties['fileS3UploaderRegion'], - 'profile'=> $this->aProperties['fileS3UploaderProfil'], - 'debug' => false - )); - if(strpos($this->aValues['key'], $sPrefix) === 0 || $sPrefix == ''){ - // récupération du fichier sur le serveur pour le téléchargement si le Etag correspond avec celui de s3 - try{ - $s3->getObject(array( - 'Bucket' => $sBucket, - 'Key' => $this->aValues['key'], - 'IfMatch' => $this->aValues['eTag'], - 'SaveAs' => $sPath + $sPath = ""; + if ($this->aProperties["filesystem"] == 's3'){ + $sPath = $this->aProperties['extract_dir'] . "/" . getUniqRandomId(); + // traitement du bucket et de ses sous-dossiers + $sBucket = $this->aProperties['fileS3UploaderBucket']; + $sPrefix = ""; + // Suppression du slash de début de ligne. + if (strpos($this->aValues["key"], '/') === 0) + $this->aValues["key"] = substr($this->aValues["key"], 1); + // + if (strpos($sBucket, "/") > -1){ + $aBucket = explode("/", $sBucket ); + $sBucket = $aBucket[0]; + $sPrefix = implode("/", array_slice($aBucket, 1)); + } + // Création du client S3 + $s3 = new Aws\S3\S3Client(array( + 'version'=>'latest', + 'region'=> $this->aProperties['fileS3UploaderRegion'], + 'profile'=> $this->aProperties['fileS3UploaderProfil'], + 'debug' => false )); - }catch(Aws\S3\Exception\S3Exception $e){ - error_log($e->getMessage()); - $bReturnFile = false; - $sMessage = array("status" => 0, "sMessage" => "This file doesn't exist or the Etag doesn't match"); - } - } else { - $bReturnFile = false; - $sMessage = array("status" => 0, "sMessage" => "You can't access to this object"); - } + if(strpos($this->aValues['key'], $sPrefix) === 0 || $sPrefix == ''){ + // récupération du fichier sur le serveur pour le téléchargement si le Etag correspond avec celui de s3 + try{ + $s3->getObject(array( + 'Bucket' => $sBucket, + 'Key' => $this->aValues['key'], + 'IfMatch' => $this->aValues['eTag'], + 'SaveAs' => $sPath + )); + }catch(Aws\S3\Exception\S3Exception $e){ + error_log($e->getMessage()); + $bReturnFile = false; + $sMessage = array("status" => 0, "sMessage" => "This file doesn't exist or the Etag doesn't match"); + } + } else { + $bReturnFile = false; + $sMessage = array("status" => 0, "sMessage" => "You can't access to this object"); + } - } else { - // modification de $sPath pour aller chercher le fichier dans ws_data - if (strpos($this->aValues["key"], 'ws_data') === 0){ - $sPath = str_replace('ws_data', $this->aProperties['ws_data_dir'], $this->aValues["key"]); - } else if (strpos($this->aValues["key"], 'public') === 0){ - $sPath = str_replace('public', $this->aProperties['dir_export'], $this->aValues["key"]); - } else if (strpos($this->aValues["key"], 'upload') === 0){ - $sPath = str_replace('upload', $this->aProperties['upload_dir'], $this->aValues["key"]); - } else if (strpos($this->aValues["key"], 'shared') === 0){ - $sPath = str_replace('shared', $properties['vas_home'] . '/shared', $this->aValues["key"]); } else { - $bReturnFile = false; - $sMessage = array("status" => 0, "sMessage" => "This directory can't be replaced by our replacer"); - } - // check eTag - $sEtag = sha1(file_get_contents($sPath), false); + // modification de $sPath pour aller chercher le fichier dans ws_data + if (strpos($this->aValues["key"], 'ws_data') === 0){ + $sPath = str_replace('ws_data', $this->aProperties['ws_data_dir'], $this->aValues["key"]); + } else if (strpos($this->aValues["key"], 'public') === 0){ + $sPath = str_replace('public', $this->aProperties['dir_export'], $this->aValues["key"]); + } else if (strpos($this->aValues["key"], 'upload') === 0){ + $sPath = str_replace('upload', $this->aProperties['upload_dir'], $this->aValues["key"]); + } else if (strpos($this->aValues["key"], 'shared') === 0){ + $sPath = str_replace('shared', $properties['vas_home'] . '/shared', $this->aValues["key"]); + } else { + $bReturnFile = false; + $sMessage = array("status" => 0, "sMessage" => "This directory can't be replaced by our replacer"); + } + // check eTag + $sEtag = sha1(file_get_contents($sPath), false); - if ($sEtag != $this->aValues['eTag']){ - $bReturnFile = false; - $sMessage = array("status" => 0, "sMessage" => "This file doesn't exist or the Etag doesn't match"); + if ($sEtag != $this->aValues['eTag']){ + $bReturnFile = false; + $sMessage = array("status" => 0, "sMessage" => "This file doesn't exist or the Etag doesn't match"); + } } - } - if($bReturnFile){ - session_write_close(); - $this->getFile($sPath, end(explode("/", $this->aValues["key"]))); - } + if($bReturnFile){ + session_write_close(); + $this->getFile($sPath, end(explode("/", $this->aValues["key"]))); + } } else { $sMessage = array("status" => 0, "sMessage" => "Missing Parameter"); @@ -164,17 +164,17 @@ class File_downloader extends Vitis { } function getFile($sFilePath, $sFileName) { - // Le fichier existe ? - if (file_exists($sFilePath)) { - $sContentType = mime_content_type($sFilePath); - header("Content-Type: " . $sContentType); - header("Content-disposition: attachment; filename=\"" . $sFileName . "\""); - header('Content-Length: ' . filesize($sFilePath)); - if ($sContentType === "application/octet-stream") { - header("Content-Transfer-Encoding: Binary"); + // Le fichier existe ? + if (file_exists($sFilePath)) { + $sContentType = mime_content_type($sFilePath); + header("Content-Type: " . $sContentType); + header("Content-disposition: attachment; filename=\"" . $sFileName . "\""); + header('Content-Length: ' . filesize($sFilePath)); + if ($sContentType === "application/octet-stream") { + header("Content-Transfer-Encoding: Binary"); + } + readfile($sFilePath); } - readfile($sFilePath); - } }