vendredi 5 avril 2019

ErrorException for uploading image in Laravel

I am trying to upload in image using an html form in my laravel blade template. But got an error in my log file like below

local.ERROR: ErrorException: copy(public/campaigns/small/91554441670ylb3chejx2freodnlo0d9ecgdlnqnbxlaaelbw1c.jpg): failed to open stream: No such file or directory in F:\Xampp\htdocs\fund\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:204

I have already googling for this but not solve yet....

I cleared cach file also using php artisan config:cache command... but not solved.

Html

<form method="POST" action="" enctype="multipart/form-data" id="formUpload">            
<div class="filer-input-inner">
    <div class="filer-input-icon">
        <i class="fa fa-cloud-upload"></i>
        </div>
        <div class="filer-input-text">
            <h3 class="margin-bottom-10"></h3>
            <h3>:  </h3>
        </div>
    </div>
</div>
<div class="box-footer">
    <hr />
    <button type="submit" id="buttonFormSubmit" class="btn btn-block btn-lg btn-main custom-rounded"></button>
</div><!-- /.box-footer -->

controller method to hand

$temp  = 'public/temp/';
$path_small    = 'public/campaigns/small/';
$path_large   = 'public/campaigns/large/';
$input      = $this->request->all();
if( $this->request->hasFile('photo') )  {

$extension    = $this->request->file('photo')->getClientOriginalExtension();
$file_large     = strtolower(Auth::user()->id.time().str_random(40).'.'.$extension);
$file_small     = strtolower(Auth::user()->id.time().str_random(40).'.'.$extension);

if( $this->request->file('photo')->move($temp, $file_large) ) {

    set_time_limit(0);

    //=============== Image Large =================//
    $width  = Helper::getWidth( $temp.$file_large );
    $height = Helper::getHeight( $temp.$file_large );
    $max_width = '800';

    if( $width < $height ) {
        $max_width = '400';
    }

    if ( $width > $max_width ) {
        $scale = $max_width / $width;
        $uploaded = Helper::resizeImage( $temp.$file_large, $width, $height, $scale, $temp.$file_large );
    } else {
        $scale = 1;
        $uploaded = Helper::resizeImage( $temp.$file_large, $width, $height, $scale, $temp.$file_large );
    }

    //=============== Small Large =================//
    Helper::resizeImageFixed( $temp.$file_large, 400, 300, $temp.$file_small );

    //======= Copy Folder Small and Delete...
    if ( \File::exists($temp.$file_small) ) {
        \File::copy($temp.$file_small, $path_small.$file_small);
        \File::delete($temp.$file_small);
    }//<--- IF FILE EXISTS

    Image::make($temp.$file_large)->orientate();

    //======= Copy Folder Large and Delete...
    if ( \File::exists($temp.$file_large) ) {
        \File::copy($temp.$file_large, $path_large.$file_large);
        \File::delete($temp.$file_large);
    }//<--- IF FILE EXISTS

}

$image_small  = $file_small;
$image_large  = $file_large;
}//<====== End HasFile

How can I solve that ? Anyone help Please ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire