如何在 laravel 中提交表单之前将图像或大文件上传到临时文件夹

How to upload Image or large file to temp folder before submit form in laravel

我正在使用此代码上传文件或图片。它正在工作,但无法上传大文件,我想在从本地计算机中选择文件时上传文件,如下图所示。

我在控制器中使用以下 PHP 代码。

$image = $request->file('file_upload');
        $new_name = rand() . '.' . $image->getClientOriginalExtension();
        echo $new_name;
        $image->move(public_path('images'), $new_name);

尝试使用此代码。

用您的字段名称更改 $request->sharing_file

您可以根据需要增加图像的 $size,目前它是 16mb 并且工作正常。

$myimage = $request->image;

$size = getClientSize();
if($sizes < 16777216){

$fileMimeType = explode('/', $myimage->getClientMimeType());
$fileType = $fileMimeType[0];

$originalFileName = substr($myimage->getClientOriginalName(), 0, strpos($myimage->getClientOriginalName(), "."));

$originalFileName = substr(str_replace(' ', '-', $originalFileName),0,10);
$rand = rand(9,1000);

$fileName = $rand.'-'.$originalFileName.'.'.$myimage->getClientOriginalExtension();

$upload = $values->move(public_path('images'), $fileName);

if($upload) {
    $message = 'File Uploaded';
} else {
    $message = "Failed to upload file";
}

}
else {
    $message = 'Files size should be less than 16 MB.';
}

尝试

       if ($request->hasFile('file_upload')) {
            $destinationPath = public_path().'/images/';
            $file = $request->file_upload;
            $fileName = time() . '.'.$file->clientExtension();
            $file->move($destinationPath, $fileName);
            $input['your_databse_table_field_name'] = $fileName;
        }