繁体   English   中英

在函数PHP中调用函数时文件未移动

[英]File not being moved when calling function inside function PHP

我目前有一个脚本可以将映像上传到服务器,我可以在另一个脚本上使用一个函数来获取$ _FILES数组并上传映像,但是该映像没有从temp目录移动到新目录,我的脚本位于和任何帮助将不胜感激谢谢

[上传脚本]

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";
}

您要在move_uploaded_file()函数中再次添加扩展名。 只需替换:

move_uploaded_file($file_tmp.$file_extension, $newDest)

move_uploaded_file($file_tmp, $newDest)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM