jeudi 16 avril 2015

File not being moved when calling function inside function PHP

I currently have a script that uploads an image to the server, i have a function on another script to take the $_FILES array and upload the image but it is not being moved from the temp directory to the new directory, my script is below and any help would be appreciated thanks


[upload script]



function upload($event_image);
$optional_img_params = "";
$img_locale = "";
if(isset($event_image)){
if($event_image['error'] == 0){
$file_name = $event_image['name'];
$file_size = $event_image['size'];
$file_tmp = $event_image['tmp_name'];
$file_type = $event_image['type'];

$allowed_exts = array('jpeg', 'jpg', 'png');
$tmp = explode('.', $file_name);
$file_extension = end($tmp);

if(in_array($file_extension, $allowed_exts) === false){
//exit('Error, file extension not supported');
$optional_img_params = "IMAGE_NOT_VALID_EXTS";
header('Location: /events-calendar');
} else if ($file_size > 10000000){
//exit('Error, file is too big in size');
$optional_img_params = "IMAGE_TOO_BIG";
header('Location: /events-calendar');
} else {
$newDest = "/home/app/public_html/userfiles/event_images/".$file_name;
$newDest1 = $file_name;
if(move_uploaded_file($file_tmp.$file_extension, $newDest)){
//echo 'Success';
$r_append = rand(1000,9999999999999).microtime();
rename("/home/app/public_html/userfiles/event_images/".$file_name, "/home/app/public_html/userfiles/event_images/".$r_append.$file_name);
$img_locale = $r_append.$newDest1;
$optional_img_params = "IMAGE_MOVED";
} else {
//echo 'Failure';
$optional_img_params = "COULDNT_MOVE_IMG=TMP=".$file_tmp.'=NEW='.$newDest;
header('Location: /events-calendar');
}
}
} else {
//exit('Error, sorry an error occurred');
$optional_img_params = "IMAGE_HAS_ERROR";
header('Location: /events-calendar');
}
} else {
$optional_img_params = "IMAGE_NOT_SET";
}

Aucun commentaire:

Enregistrer un commentaire