Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added file prefix param to MooUpload::upload() method

  • Loading branch information...
commit 425e3d5d65dcd45c10c620e98541dadf9117ab19 1 parent 68970f1
@juanparati authored
Showing with 8 additions and 7 deletions.
  1. +8 −7 Source/mooupload.php
View
15 Source/mooupload.php
@@ -36,12 +36,13 @@ public static function is_HTML5_upload()
*
* Upload a file using HTML4 or Flash method
*
- * @param string Directory destination path
+ * @param string Directory destination path
+ * @param string File prefix (Useful for avoid file overwriting)
* @param boolean Return response to the script
* @return array Response
*
*/
- public static function HTML4_upload($destpath, $send_response = TRUE)
+ public static function HTML4_upload($destpath, $file_prefix = '', $send_response = TRUE)
{
// Normalize path
@@ -65,7 +66,7 @@ public static function HTML4_upload($destpath, $send_response = TRUE)
if ($response['error'] == 0)
{
- if (move_uploaded_file($file['tmp_name'], $destpath.$file['name']) === FALSE)
+ if (move_uploaded_file($file['tmp_name'], $destpath.$file_prefix.$file['name']) === FALSE)
$response['error'] = UPLOAD_ERR_NO_TMP_DIR;
else
$response['finish'] = TRUE;
@@ -90,7 +91,7 @@ public static function HTML4_upload($destpath, $send_response = TRUE)
* @return array Response
*
*/
- public static function HTML5_upload($destpath, $send_response = TRUE)
+ public static function HTML5_upload($destpath, $file_prefix = '', $send_response = TRUE)
{
// Normalize path
@@ -148,7 +149,7 @@ public static function HTML5_upload($destpath, $send_response = TRUE)
$response['finish'] = TRUE;
/* If uploaded file is finished, maybe you are interested in saving, registering or moving the file */
- // my_save_file($destpath.$filename, $response['name']);
+ // my_save_file($destpath.$filename, $file_prefix.$response['name']);
}
}
@@ -175,9 +176,9 @@ public static function HTML5_upload($destpath, $send_response = TRUE)
* @return array Response
*
*/
- public static function upload($destpath, $send_response = TRUE)
+ public static function upload($destpath, $file_prefix = '', $send_response = TRUE)
{
- return self::is_HTML5_upload() ? self::HTML5_upload($destpath, $send_response) : self::HTML4_upload($destpath, $send_response);
+ return self::is_HTML5_upload() ? self::HTML5_upload($destpath, $file_prefix, $send_response) : self::HTML4_upload($destpath, $file_prefix, $send_response);
}
Please sign in to comment.
Something went wrong with that request. Please try again.