重命名已经存在的上传文件并重新上传

bkkx9g8r  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(177)

我正在尝试重命名一个上载的文件,该文件要重命名并上载,重命名的文本在我的数据库及其文件路径中被更改,
请帮帮我?
这是我的代码,我是一个初学者在php mysql..我需要一个解决方案,请?
如果有人知道尽可能重新编辑我的代码,请帮助我兄弟们?

if(isset($_FILES["file"]))
        {
            $path = "../../assets/uploads/company/1_SourceSol/"; 

            if(!file_exists($path.$dir))
            {
                mkdir($path.$dir, 0777, true);
            }
            $target_dir = $path.$dir."/";
            $target_file = $target_dir . basename($_FILES["file"]["name"]);
            $uploadOk = 1;
            $fileType = pathinfo($target_file,PATHINFO_EXTENSION);

            if(trim($_REQUEST['file_rename'])!='')
            {
                $target_file=$target_dir . basename(trim($_REQUEST['file_rename'])).'.'.$fileType;
                $file_rename=basename(trim($_REQUEST['file_rename']));
            }

            // Check if file already exists
            if (file_exists($target_file)) {
                $error="Sorry, file already exists.";
                $uploadOk = 1;
            }
            // Check file size
            if ($_FILES["file"]["size"] > 500000) {
                $error="Sorry, your file is too large.";
                $uploadOk = 1;
            }

            // Check if $uploadOk is set to 0 by an error
            if ($uploadOk == 0) {
                $error="Sorry, file was not uploaded.";
            } 

            else
            {
                if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file))
                {
                    sleep(1);
                    $message="The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";

                    $query="UPDATE `topview_logo`
                            SET 
                            `topview_id`        = '$topview_id',
                            `filename`      = '$target_file',
                            `file_rename`       = '$file_rename'    
                            WHERE 
                            `company_logo_id`   = '$company_logo_id'";
                    mysqli_query($link,$query) or die(mysqli_error($link));
                } 

            } 
        }

            else
            {
                $query="UPDATE `topview_logo`
                        SET 
                        `topview_id`        = '$topview_id',
                        `file_rename`       = '$file_rename'
                        WHERE 
                        `company_logo_id`   = '$company_logo_id'";
                mysqli_query($link,$query) or die(mysqli_error($link));
            }
        }           
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题