Skip to content
Snippets Groups Projects
Commit 2eb1ae1a authored by Anthony Borghi's avatar Anthony Borghi
Browse files

Ajout de la fonctionnalité pour envoyer les fichiers sur S3

Prise en charge d'un préfixe concaténé avec le bucket dans la properties PHP
parent 9b10b663
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
* @brief Fonctions php diverses * @brief Fonctions php diverses
* *
* @author Fabien Marty <fabien.marty@veremes.com> * @author Fabien Marty <fabien.marty@veremes.com>
* @author Yoann Perollet <yoann.perollet@veremes.com>
* @author Armand Bahi <armand.bahi@veremes.com>
* @author Anthony Borghi <anthony.borghi@veremes.com>
*/ */
/* /*
* Variable globale stockant le nom de dossier lib. * Variable globale stockant le nom de dossier lib.
...@@ -118,7 +121,36 @@ function uploadFile($sNomObjet, $sFileType, $sServerPath, $sMaxSize, $aFileValue ...@@ -118,7 +121,36 @@ function uploadFile($sNomObjet, $sFileType, $sServerPath, $sMaxSize, $aFileValue
//Lance l'upload. //Lance l'upload.
if ($bAllowUpload) { if ($bAllowUpload) {
if (!copy($sTmpFile, $sServerPath)) { if ($properties['fileS3Uploader']){
require_once ("aws_sdk/aws-autoloader.php");
$s3 = new Aws\S3\S3Client(array(
'version'=>'latest',
'region'=> $properties['fileS3UploaderRegion'],
'profile'=> $properties['fileS3UploaderProfil'],
'debug' => false
));
$sBucket = $properties['fileS3UploaderBucket'];
$sPrefix = "";
if (strpos($sBucket, "/") > -1){
$aBucket = explode("/", $sBucket );
$sBucket = $aBucket[0];
$sPrefix = implode("/", array_slice($aBucket, 1));
}
$sServerPath = str_replace($properties["vas_home"], $sPrefix , $sServerPath);
$aResult = $s3->putObject(array(
'Bucket' => $sBucket,
'Key' => $sServerPath,
'Body' => file_get_contents($sTmpFile)
));
error_log(print_r($aResult, true));
} else if (!copy($sTmpFile, $sServerPath)) {
writeToErrorLog(ERROR_COPYING_FILE . $aFileValues['name'] . ON_SERVER_PHPUTIL . ', ' . $sTmpFile . ', ' . $sServerPath); writeToErrorLog(ERROR_COPYING_FILE . $aFileValues['name'] . ON_SERVER_PHPUTIL . ', ' . $sTmpFile . ', ' . $sServerPath);
$sErrorMsg = ERROR_COPYING_FILE . $aFileValues['name'] . ON_SERVER_PHPUTIL . '.'; $sErrorMsg = ERROR_COPYING_FILE . $aFileValues['name'] . ON_SERVER_PHPUTIL . '.';
} }
...@@ -226,7 +258,7 @@ function uploadInWsDataDir ($sModule, $sObject, $mId, $sField, $aValues, $iMaxSi ...@@ -226,7 +258,7 @@ function uploadInWsDataDir ($sModule, $sObject, $mId, $sField, $aValues, $iMaxSi
$iMaxSize = $aFileStruct["size"] + 1; $iMaxSize = $aFileStruct["size"] + 1;
} }
// création du fichier si besoin // création du fichier si besoin
if (!is_dir($sDestDir)){ if (!is_dir($sDestDir) && !$properties['fileS3Uploader']){
if(!mkdir($sDestDir, 0777, true)){ if(!mkdir($sDestDir, 0777, true)){
writeToErrorLog("Can't create directory " . $sDestDir); writeToErrorLog("Can't create directory " . $sDestDir);
return "Can't create directory " . $sDestDir; return "Can't create directory " . $sDestDir;
...@@ -279,7 +311,7 @@ function uploadInPublicDir($sModule, $sField, $aValues, $sRandomUniqId = "auto", ...@@ -279,7 +311,7 @@ function uploadInPublicDir($sModule, $sField, $aValues, $sRandomUniqId = "auto",
} }
// création du fichier si besoin // création du fichier si besoin
if (!is_dir($sDestDir)){ if (!is_dir($sDestDir) && !$properties['fileS3Uploader']){
if(!mkdir($sDestDir, 0777, true)){ if(!mkdir($sDestDir, 0777, true)){
writeToErrorLog("Can't create directory " . $sDestDir); writeToErrorLog("Can't create directory " . $sDestDir);
return "Can't create directory " . $sDestDir; return "Can't create directory " . $sDestDir;
...@@ -333,7 +365,7 @@ function uploadInUploadDir($sModule, $sField, $aValues, $sRandomUniqId = "auto", ...@@ -333,7 +365,7 @@ function uploadInUploadDir($sModule, $sField, $aValues, $sRandomUniqId = "auto",
} }
// création du fichier si besoin // création du fichier si besoin
if (!is_dir($sDestDir)){ if (!is_dir($sDestDir) && !$properties['fileS3Uploader']){
if(!mkdir($sDestDir, 0777, true)){ if(!mkdir($sDestDir, 0777, true)){
writeToErrorLog("Can't create directory " . $sDestDir); writeToErrorLog("Can't create directory " . $sDestDir);
return "Can't create directory " . $sDestDir; return "Can't create directory " . $sDestDir;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment