diff --git a/module/doc/control.php b/module/doc/control.php
index a98bd09dde..16822926ca 100755
--- a/module/doc/control.php
+++ b/module/doc/control.php
@@ -616,6 +616,7 @@ class doc extends control
*/
public function delete($docID, $confirm = 'no', $from = 'list')
{
+ $this->loadModel('file');
if($confirm == 'no')
{
$type = $this->dao->select('type')->from(TABLE_DOC)->where('id')->eq($docID)->fetch('type');
@@ -637,7 +638,7 @@ class doc extends control
$this->loadModel('action')->create($file->objectType, $file->objectID, 'deletedFile', '', $extra=$file->title);
$fileRecord = $this->dao->select('id')->from(TABLE_FILE)->where('pathname')->eq($file->pathname)->fetch();
- if(empty($fileRecord)) @unlink($file->realPath);
+ if(empty($fileRecord)) $this->file->unlinkFile($file);
}
/* if ajax request, send result. */
diff --git a/module/doc/model.php b/module/doc/model.php
index 48d24222c1..956b9132ee 100644
--- a/module/doc/model.php
+++ b/module/doc/model.php
@@ -643,9 +643,7 @@ class docModel extends model
{
foreach($files as $file)
{
- $pathName = $this->file->getRealPathName($file->pathname);
- $file->webPath = $this->file->webPath . $pathName;
- $file->realPath = $this->file->savePath . $pathName;
+ $this->loadModel('file')->setFileWebAndRealPaths($file);
if(strpos(",{$docContent->files},", ",{$file->id},") !== false) $docFiles[$file->id] = $file;
}
}
@@ -1748,9 +1746,7 @@ class docModel extends model
foreach($files as $fileID => $file)
{
- $pathName = $this->file->getRealPathName($file->pathname);
- $file->realPath = $this->file->savePath . $pathName;
- $file->webPath = $this->file->webPath . $pathName;
+ $this->file->setFileWebAndRealPaths($file);
}
return $files;
diff --git a/module/doc/view/showfiles.html.php b/module/doc/view/showfiles.html.php
index 9266493800..ceee6b1376 100644
--- a/module/doc/view/showfiles.html.php
+++ b/module/doc/view/showfiles.html.php
@@ -84,12 +84,8 @@
extension) !== false and file_exists($file->realPath))
- {
- $imageSize = getimagesize($file->realPath);
- $imageWidth = $imageSize ? $imageSize[0] : 0;
- }
+ $imageSize = $this->loadModel('file')->getImageSize($file);
+ $imageWidth = $imageSize[0];
$fileID = $file->id;
$url = helper::createLink('file', 'download', 'fileID=' . $fileID);
diff --git a/module/file/control.php b/module/file/control.php
index c4b3770221..3f610b3765 100755
--- a/module/file/control.php
+++ b/module/file/control.php
@@ -146,7 +146,7 @@ class file extends control
$file->extension = $extension;
}
- if(file_exists($file->realPath))
+ if($this->file->fileExists($file))
{
/* If the mode is open, locate directly. */
if($mode == 'open')
@@ -290,7 +290,7 @@ class file extends control
/* Fix Bug #1518. */
$fileRecord = $this->dao->select('id')->from(TABLE_FILE)->where('pathname')->eq($file->pathname)->fetch();
- if(empty($fileRecord)) @unlink($file->realPath);
+ if(empty($fileRecord)) $this->file->unlinkFile($file);
/* Update test case version for test case synchronization. */
if($file->objectType == 'testcase') $this->file->updateTestcaseVersion($file);
@@ -500,7 +500,7 @@ class file extends control
public function read($fileID)
{
$file = $this->file->getById($fileID);
- if(empty($file) or !file_exists($file->realPath)) return false;
+ if(empty($file) or !$this->file->fileExists($file)) return false;
$obLevel = ob_get_level();
for($i = 0; $i < $obLevel; $i++) ob_end_clean();
diff --git a/module/file/model.php b/module/file/model.php
index 9fe5e57900..e5832e2ef0 100755
--- a/module/file/model.php
+++ b/module/file/model.php
@@ -60,9 +60,7 @@ class fileModel extends model
continue;
}
- $realPathName = $this->getRealPathName($file->pathname);
- $file->realPath = $this->savePath . $realPathName;
- $file->webPath = $this->webPath . $realPathName;
+ $this->setFileWebAndRealPaths($file);
}
return $files;
@@ -88,9 +86,7 @@ class fileModel extends model
return $file;
}
- $realPathName = $this->getRealPathName($file->pathname);
- $file->realPath = $this->savePath . $realPathName;
- $file->webPath = $this->webPath . $realPathName;
+ $this->setFileWebAndRealPaths($file);
return $file;
}
@@ -117,9 +113,7 @@ class fileModel extends model
continue;
}
- $realPathName = $this->getRealPathName($file->pathname);
- $file->realPath = $this->savePath . $realPathName;
- $file->webPath = $this->webPath . $realPathName;
+ $this->setFileWebAndRealPaths($file);
}
return $files;
@@ -487,6 +481,20 @@ class fileModel extends model
$this->webPath = $this->app->getWebRoot() . "data/upload/{$this->app->company->id}/";
}
+ /**
+ * Set paths: realPath and webPath.
+ *
+ * @param object $file
+ * @access public
+ * @return void
+ */
+ public function setFileWebAndRealPaths(&$file)
+ {
+ $pathName = $this->getRealPathName($file->pathname);
+ $file->realPath = $this->savePath . $pathName;
+ $file->webPath = $this->webPath . $pathName;
+ }
+
/**
* Insert the set image size code.
*
@@ -512,6 +520,30 @@ class fileModel extends model
return str_replace(' src="data/upload', ' onload="setImageSize(this,' . $maxSize . ')" src="data/upload', $content);
}
+ /**
+ * Check file exists or not.
+ *
+ * @param object $file
+ * @access public
+ * @return bool
+ */
+ public function fileExists($file)
+ {
+ return file_exists($file->realPath);
+ }
+
+ /**
+ * Unlink file.
+ *
+ * @param object $file
+ * @access public
+ * @return bool|null
+ */
+ public function unlinkFile($file)
+ {
+ return @unlink($file->realPath);
+ }
+
/**
* Replace a file.
*
@@ -1021,7 +1053,7 @@ class fileModel extends model
{
$file = $this->getById($imageID);
$this->dao->delete()->from(TABLE_FILE)->where('id')->eq($imageID)->exec();
- @unlink($file->realPath);
+ $this->unlinkFile($file);
}
}
unset($_SESSION['album'][$uid]);
@@ -1087,9 +1119,12 @@ class fileModel extends model
*/
public function getImageSize($file)
{
+
+ if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) === false) return array(0, 0, $$file->extension);
+
if($this->config->file->storageType == 'fs')
{
- return file_exists($file->realPath) ? getimagesize($file->realPath) : 0;
+ return file_exists($file->realPath) ? getimagesize($file->realPath) : array(0, 0, $$file->extension);
}
else if($this->config->file->storageType == 's3')
{
@@ -1155,7 +1190,7 @@ class fileModel extends model
$this->dao->delete()->from(TABLE_FILE)->where('id')->in($deleteFiles)->exec();
foreach($deleteFiles as $fileID)
{
- @unlink($oldObject->files[$fileID]->realPath);
+ $this->unlinkFile($oldObject->files[$fileID]);
$oldFiles = empty($oldFiles) ? '' : trim(str_replace(",$fileID,", ',', ",$oldFiles,"), ',');
}
}
@@ -1167,4 +1202,28 @@ class fileModel extends model
$newObject->files = trim($oldFiles . $addedFiles, ',');
$oldObject->files = join(',', array_keys($oldObject->files));
}
+
+ /**
+ * Get last modified timestamp of file.
+ *
+ * @param object $file
+ * @access public
+ * @return int
+ */
+ public function fileMTime($file)
+ {
+ return filemtime($file->realPath);
+ }
+
+ /**
+ * Get file size.
+ *
+ * @param object $file
+ * @access public
+ * @return int
+ */
+ public function fileSize($file)
+ {
+ return filesize($file->realPath);
+ }
}
diff --git a/module/file/view/printfiles.html.php b/module/file/view/printfiles.html.php
index ee78a6ecc0..9943b67a0d 100644
--- a/module/file/view/printfiles.html.php
+++ b/module/file/view/printfiles.html.php
@@ -54,12 +54,9 @@
$uploadDate = $lang->file->uploadDate . substr($file->addedDate, 0, 10);
$fileTitle = " " . $file->title;
if(strpos($file->title, ".{$file->extension}") === false && $file->extension != 'txt') $fileTitle .= ".{$file->extension}";
- $imageWidth = 0;
- if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
- {
- $imageSize = $this->file->getImageSize($file);
- $imageWidth = $imageSize ? $imageSize[0] : 0;
- }
+
+ $imageSize = $this->file->getImageSize($file);
+ $imageWidth = $imageSize[0];
$fileSize = 0;
/* Show size info. */
diff --git a/module/file/view/viewfiles.html.php b/module/file/view/viewfiles.html.php
index a41d89589d..c941508472 100644
--- a/module/file/view/viewfiles.html.php
+++ b/module/file/view/viewfiles.html.php
@@ -38,8 +38,8 @@ $(document).ready(function()
/**
* Delete a file.
*
- * @param int $fileID
- * @param object $obj
+ * @param int fileID
+ * @param object obj
* @access public
* @return void
*/
@@ -58,10 +58,10 @@ function deleteFile(fileID, obj)
/**
* Download a file, append the mouse to the link. Thus we call decide to open the file in browser no download it.
*
- * @param int $fileID
- * @param int $extension
- * @param int $imageWidth
- * @param string $fileTitle
+ * @param int fileID
+ * @param int extension
+ * @param int imageWidth
+ * @param string fileTitle
* @access public
* @return void
*/
@@ -157,7 +157,7 @@ function setFileName(fileID)
if(stripos('jpg|jpeg|gif|png|bmp', $file->extension) !== false)
{
$imageSize = $this->file->getImageSize($file);
- $imageWidth = $imageSize ? $imageSize[0] : 0;
+ $imageWidth = $imageSize[0];
}
$fileSize = 0;
diff --git a/module/testtask/model.php b/module/testtask/model.php
index d0e3767943..3994789255 100755
--- a/module/testtask/model.php
+++ b/module/testtask/model.php
@@ -1397,9 +1397,7 @@ class testtaskModel extends model
$stepFiles = array();
foreach($files as $file)
{
- $pathName = $this->file->getRealPathName($file->pathname);
- $file->webPath = $this->file->webPath . $pathName;
- $file->realPath = $this->file->savePath . $pathName;
+ $this->file->setFileWebAndRealPaths($file);
if($file->objectType == 'caseResult')
{
$resultFiles[$file->objectID][$file->id] = $file;