Skip to content
Snippets Groups Projects
Commit 45a1cad9 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
Ajout de commentaires dans la partie S3
parent 9b10b663
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,9 @@
* @brief Fonctions php diverses
*
* @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.
......@@ -118,7 +121,34 @@ function uploadFile($sNomObjet, $sFileType, $sServerPath, $sMaxSize, $aFileValue
//Lance l'upload.
if ($bAllowUpload) {
if (!copy($sTmpFile, $sServerPath)) {
if ($properties['fileS3Uploader']){
require_once ("aws_sdk/aws-autoloader.php");
// Création du client S3
$s3 = new Aws\S3\S3Client(array(
'version'=>'latest',
'region'=> $properties['fileS3UploaderRegion'],
'profile'=> $properties['fileS3UploaderProfil'],
'debug' => false
));
// traitement du bucket et de ses sous-dossiers
$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);
// envoi de l'objet sur S3
$aResult = $s3->putObject(array(
'Bucket' => $sBucket,
'Key' => $sServerPath,
'Body' => file_get_contents($sTmpFile)
));
} else if (!copy($sTmpFile, $sServerPath)) {
writeToErrorLog(ERROR_COPYING_FILE . $aFileValues['name'] . ON_SERVER_PHPUTIL . ', ' . $sTmpFile . ', ' . $sServerPath);
$sErrorMsg = ERROR_COPYING_FILE . $aFileValues['name'] . ON_SERVER_PHPUTIL . '.';
}
......@@ -226,7 +256,7 @@ function uploadInWsDataDir ($sModule, $sObject, $mId, $sField, $aValues, $iMaxSi
$iMaxSize = $aFileStruct["size"] + 1;
}
// création du fichier si besoin
if (!is_dir($sDestDir)){
if (!is_dir($sDestDir) && !$properties['fileS3Uploader']){
if(!mkdir($sDestDir, 0777, true)){
writeToErrorLog("Can't create directory " . $sDestDir);
return "Can't create directory " . $sDestDir;
......@@ -279,7 +309,7 @@ function uploadInPublicDir($sModule, $sField, $aValues, $sRandomUniqId = "auto",
}
// création du fichier si besoin
if (!is_dir($sDestDir)){
if (!is_dir($sDestDir) && !$properties['fileS3Uploader']){
if(!mkdir($sDestDir, 0777, true)){
writeToErrorLog("Can't create directory " . $sDestDir);
return "Can't create directory " . $sDestDir;
......@@ -333,7 +363,7 @@ function uploadInUploadDir($sModule, $sField, $aValues, $sRandomUniqId = "auto",
}
// création du fichier si besoin
if (!is_dir($sDestDir)){
if (!is_dir($sDestDir) && !$properties['fileS3Uploader']){
if(!mkdir($sDestDir, 0777, true)){
writeToErrorLog("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