Skip to content
Snippets Groups Projects
Commit 916bfb9e authored by Frédéric Carretero's avatar Frédéric Carretero
Browse files

fileExistsInWsDataDir() -> Teste si un fichier existe dans "ws_data"

parent fa7e9ab5
No related branches found
No related tags found
No related merge requests found
......@@ -1709,4 +1709,63 @@ function isDirInWsDataDir($sModule, $sObject, $mId, $sDirectoryName = '') {
return false;
}
}
/**
*This method return the content of a file in ws_data.
*@file vmlib/phpUtil.inc
*@param $sModule Name of the module.
*@param $sObject Name of the object.
*@param $mId Id of the current object.
*@param $sDirectory directory name (optionnal).
*@param $sFileName Name of the file to read.
*@return true or false.
*/
function fileExistsInWsDataDir($sModule, $sObject, $mId, $sDirectory = '', $sFileName) {
global $properties;
$sDestDir = $properties['ws_data_dir'] . "/" . $sModule . "/" . $sObject . "/" . $mId;
if(!empty($sDirectory))
$sDestDir .= "/" . $sDirectory;
if ($properties['fileS3Uploader'] === true) {
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, $sDestDir);
// Suppression du slash de début de ligne (sinon création d'un répertoire vide sur S3).
if (strpos($sServerPath, '/') === 0)
$sServerPath = substr($sServerPath, 1);
if (!empty($sFileName))
$sServerPath .= '/' . $sFileName;
// Lecture du fichier.
try {
$oAwsResult = $s3->getObject(array(
'Bucket' => $sBucket,
'Key' => $sServerPath
));
return true;
}
catch(Aws\S3\Exception\S3Exception $e) {
writeToErrorLog($e->getMessage());
return false;
}
}
else {
// Teste si le fichier existe.
$sFilePath = $sDestDir . '/' . $sFileName;
if (file_exists($sFilePath))
return true;
else
return false;
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment