Select Git revision
Local_files.class.inc
Forked from
Open source / vMap
Source project has a limited visibility.
Local_files.class.inc 4.46 KiB
<?php
require_once ("Files.interface.inc");
class Local_files implements Files{
var $oProperties;
function __construct($properties){
$this->oProperties = $properties;
}
/**
*This method return the extension of a file.
*@param string $sFilePath File's path.
*@return string|boolean hash sha1 of file content or false if the file doesn't exist.
*/
public function getFileEtag($sFilePath){
if(file_exists($sFilePath)){
return sha1(file_get_contents($sFilePath), false);
} else {
return false;
}
}
/**
*verify if a file exists.
*@param string $sFilePath File's path.
*@return boolean true if file exists, false else.
*/
public function file_exists ($sFilePath){
return file_exists($sFilePath);
}
/**
*Write a string in a file.
*@param string $sFilePath File's path.
*@param string $sData string to write in this file.
*@param integer $iFlags flags to write in file (http://php.net/manual/fr/function.file-put-contents.php) Default : 0.
*@param resource $mContext result de stream_context_create().
*@return integer|boolean number of byte written, or false if the process encounter an error.
*/
public function file_put_contents ($sFilePath, $sData, $iFlags = 0, $mContext = null){
return file_put_contents($sFilePath, $sData, $iFlags, $mContext);
}
public function file_get_contents ($sFilePath, $bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){
if ($iMaxLen == -1){
return file_get_contents ($sFilePath, $bUseIncludePath, null, $iOffset);
} else {
return file_get_contents ($sFilePath, $bUseIncludePath, null, $iOffset, $iMaxLen);
}
}
public function file_get_contents_with_etag ($sFilePath, $sEtag ,$bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){
$sProcessedEtag = $this->getFileEtag($sFilePath);
if ($sEtag == $sProcessedEtag){
return $this->file_get_contents($sFilePath, $bUseIncludePath, $mContext, $iOffset, $iMaxLen);
} else {
return false;
}
}
public function copy ($sSourceFilePath, $sDestFilePath){
return copy ($sSourceFilePath, $sDestFilePath);
}
public function filesize ($sFilePath){
return filesize($sFilePath);
}
public function readfile ($sFilePath, $bUseIncludePath = FALSE, $mContext = null){
return readfile($sFilePath, $bUseIncludePath, $mContext);
}
public function rename ($sSourceFilePath, $sDestFilePath, $mContext = null){
if(empty($mContext)){
return rename($sSourceFilePath, $sDestFilePath);
}else{
return rename($sSourceFilePath, $sDestFilePath, $mContext);
}
}
public function unlink ($sFilePath, $mContext = null){
if(empty($mContext)){
return unlink($sFilePath);
} else {
return unlink($sFilePath, $mContext);
}
}
public function filemtime ($sFilePath){
return filemtime($sFilePath);
}
public function filemtime_formated($sFilePath, $sFormat){
return date ($sFormat, $this->filemtime($sFilePath));
}
public function getFileInfos ($sFilePath){
$iFileSize = $this->filesize($sFilePath);
$sFileSize = $iFileSize . " octets";
if($iFileSize > 1024){
if($iFileSize > 1024*1024){
if($iFileSize > 1024*1024*1024){
$sFileSize = "-";
} else {
$sFileSize = (ceil($iFileSize/(1024*1024))) . "Mo";
}
}else{
$sFileSize = (ceil($iFileSize/1024)) . "Ko";
}
}
$aFileName = explode("/", $sFilePath);
return array("filename"=>$aFileName[count($aFileName) - 1], "size"=>$sFileSize, "lastModification"=> $this->filemtime_formated ($sFilePath, "d/m/Y H:i:s"), "href" => $this->getProxyPassUrl($sFilePath));
}
public function getProxyPassUrl ($sFilePath){
$date = new DateTime();
$sDataUrl = $this->oProperties['web_server_name'] . "/rest/vitis/file_downloader?key=[KEY]&eTag=[ETAG]&d=" . $date->getTimestamp();
$sFileUrl = str_replace("[KEY]", str_replace($this->oProperties['ws_data_dir'], "ws_data" , $sFilePath), $sDataUrl);
$sFileUrl = str_replace("[ETAG]", sha1(file_get_contents($sFilePath), false), $sFileUrl);
return $sFileUrl;
}
}
?>