Skip to content

Commit

Permalink
Changed @return API of File->upload() returning the complete file…
Browse files Browse the repository at this point in the history
… upload information of `name`, `fileName`, `extension`, `dir` and `uploads`.
  • Loading branch information
dev-sithu committed Mar 27, 2015
1 parent 86bfb74 commit 02d4c6c
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions helpers/file_helper.php
Expand Up @@ -48,6 +48,8 @@ class File{
private $originalFileName;
/** @var string The file name generated */
private $fileNameBased;
/** @var array The uploaded file information */
private $uploads;

/**
* Constructor
Expand Down Expand Up @@ -99,17 +101,27 @@ public function getFileNameBased(){
* If the uploaded file is image, this will create the various images according to the given $dimension
*
* @param array $file The uploaded file information from $_FILES['xxx']
* @param array Th array of the uploaded files,
* for example,
* uploaded[dimension] = "file-name" for image files or uploaded[] = "file-name" for the files of other types
*
* @return array The array of the uploaded file information:
*
* array(
* 'name' => 'Name of the input element',
* 'fileName' => 'The original file name',
* 'extension'=> 'The selected and uploaded file extension',
* 'dir' => 'The uploaded directory',
* 'uploads' => array(
* 'dimension (WxH) or index' => 'The uploaded file name like return from basename()'
* )
* )
*
*/
public function upload($file){
$fileName = stripslashes($file['name']);
$uploadedFile = $file['tmp_name'];
$info = pathinfo($fileName);
$extension = strtolower($info['extension']);
$uploaded = false;
$path = $this->uploadPath;
$fileName = stripslashes($file['name']);
$uploadedFile = $file['tmp_name'];
$info = pathinfo($fileName);
$extension = strtolower($info['extension']);
$uploaded = null;
$path = $this->uploadPath;

if($fileName && $uploadedFile){
$this->originalFileName = $fileName;
Expand Down Expand Up @@ -160,7 +172,18 @@ public function upload($file){
}
}
}
return $uploaded;

if($uploaded){
$this->uploads = array(
'name' => $this->name,
'fileName' => $this->originalFileName,
'extension'=> $extension,
'dir' => $this->uploadPath,
'uploads' => $uploaded
);
}

return $this->uploads;
}
/**
* Get a new file name, e.g., original-file-name-[imageWidth]-[uniqueId].ext
Expand Down

0 comments on commit 02d4c6c

Please sign in to comment.