vendredi 15 février 2019

Files not uploading due to unkown error using laravel

  • Laravel Version: 5.5

I have a problem when uploading a file. I have multiple files in the array, I am uploading these files two times in the same function for the first time I am checking pdf file version, and file dimensions this block of code works perfectly but in the second block of code I am again uploading these files for merging these files it gives me this error "The file "A4.pdf" was not uploaded due to an unknown error". When I remove the first block of code then the second block of code start working.I don't know where I did mistake, I have searched a lot but not found the answer.

This block of code checking pdf file version and dimensions.

$paper_size = array();
$del_files = array();
foreach ($files as $file) {

        $filename = time().date('m-d-y').$file->getClientOriginalName();

        $file->move(public_path().'/uploads/check_pdf_files/', $filename);

        $version = $this->pdfVersion(public_path().'/uploads/check_pdf_files/'.$filename);

        if($version > 1.5)
        {
            File::delete('public/uploads/check_pdf_files/'.$filename);

            return Response::json(" Your PDF file version is greater than 1.4 which is not compatible with our system, Please make it lower version.", 400);
        }

        $get_paper_size = $this->get_pdf_dimensions('public/uploads/check_pdf_files/'.$filename);

        $paper_size[] = $get_paper_size;
        $del_files[] = $filename;
    }

    if(round($paper_size[0]['width']) != round($paper_size[1]['width']))
    {
        foreach ($del_files as $del) 
        {
            File::delete('public/uploads/check_pdf_files/'.$del);
        }

        return Response::json(" Your Files dimensions is not matching please try with same dimensions.", 400);
    }

This block of code using for merging the files.

         $new_pdf_file = array();

         foreach ($request->file as $merge_file) 
            {
                $newFile_name = time().$merge_file->getClientOriginalName();


                $merge_file->move('public/uploads/', $newFile_name);

                $new_pdf_file[] = $newFile_name;
            }
            dd($new_pdf_file);

            $pdf = new \LynX39\LaraPdfMerger\PdfManage;

            foreach($new_pdf_file as $new)
            {
                $pdf->addPDF('public/uploads/dummy_uploads/'.$new, 'all');
            }

            $temp_name = time().$request->merge_name;

            $pdf->merge('file',base_path(). '/public/uploads/' . Auth::user()->email . '/'.$temp_name.'.pdf', 'P');

            foreach($new_pdf_file as $delete_new)
            {
                File::delete('public/uploads/dummy_uploads/'.$delete_new);
            }

            $user = DB::table('user_pdf_files')->insert([
                'user_files' => $request->merge_name.'.pdf',
                'filename' => $temp_name.'.pdf',
                'type' => $request->type[0],
                'user_id'    => Auth::user()->id,
            ]);

            Session::flash('success', 'Files Merged Successfully');
            return Response::json('success', 200);`



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire