/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
How can I improve the name check part or another things?
/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
How can I improve the name check part or another things?
How could how can I run this function on php 5.4improve the check name file part
I have this function working on php 5.3
/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype, $_FILES) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
But when I include this function in another project that run over php 5.4 I get
500 Internal Server Error
Just including this function without call it, I get the error.
What is the issue here?
How could I run this function on php 5.4
I have this function working on php 5.3
/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype, $_FILES) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
But when I include this function in another project that run over php 5.4 I get
500 Internal Server Error
Just including this function without call it, I get the error.
What is the issue here?
how can I improve the check name file part
/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
How could I run this function on php 5.4
I have this function working on php 5.3
/**
* Upload has a limit of 10 mb
* @param string $dir $_SERVER['DOCUMENT_ROOT']
* @param string $path Path do you want to upload the file
* @param string $filetype jpg|jpeg|gif|png|doc|docx|txt|rtf|pdf|xls|xlsx|ppt|pptx
* @param array $_FILES An associative array of items uploaded to the current script via the HTTP POST method.
* @return string ?$fileName:False
*/
function uploadFiles($dir, $path, $filetype, $_FILES) {
$dir_base = "{$dir}{$path}";
$dateadded = date('ynj_Gis-');
$rEFileTypes = "/^\.($filetype){1}$/i";
$MAXIMUM_FILESIZE = 10 * 1024 * 1024;
// UPLOAD IMAGES
$isFile = is_uploaded_file($_FILES['file']['tmp_name']);
if ($isFile) {
$safe_filename = $dateadded . preg_replace(array('/\s+/', '/[^-\.\w]+/'), array('_', ''), trim($_FILES['file']['name']));
if ($_FILES['file']['size'] <= $MAXIMUM_FILESIZE && preg_match($rEFileTypes, strrchr($safe_filename, '.'))) {
$isMove = move_uploaded_file($_FILES['file']['tmp_name'], $dir_base . $safe_filename);
}
}
if ($isMove) {
return $safe_filename;
} else {
return false;
}
}
But when I include this function in another project that run over php 5.4 I get
500 Internal Server Error
Just including this function without call it, I get the error.
What is the issue here?