Home redirect is not working even though i see the response - Laravel
Reply: 0

redirect is not working even though i see the response - Laravel

user1851
1#
user1851 Published in May 20, 2018, 12:01 pm

i am building a project which upload files to modify. I want to redirect to other page when uploading finishes. Redirecting is not working even though i see the response (the page html which i want to go to). here is a sample of what happens when uploading finishes:

Here is my uploading code in JavaScript:

$('#fileupload').fileupload({
    dataType: 'json',
     maxChunkSize: 10000000, 
    maxFileSize: 1000000 * 10000,
    done: function (e, data) {
      console.log("success");
      $('#spin').css('display','none');

    },
    progress:function (e, data) {
    var progress = parseInt(data.loaded / data.total * 100, 10);
      $('#prog').html(progress+"%");
      $('#prog').width(''+progress+'%');
      if(progress == 100){
          $("#prog").html('Completed');
          $('#spin').css('display','block');
      }
      console.log(progress);
    }

});

the function that saves the uploaded file (contains the redirect response) , it exists in the "UploadsController" controller:

protected function saveFile(UploadedFile $file)
{
    $fileName = $file->getClientOriginalName();
    $finalPath = storage_path() . '/app/upload/';
    $file->move($finalPath, $fileName);//save uploaded file


    if (strcmp($file->getClientOriginalExtension(), "zip") == 0) { // if it is a zip file


            return redirect('download'); // redirect


    } else { // if it is not a zip file

        Storage::delete('/upload/' . $fileName);
        return response()->json([
            'status' => 'Zfalse'
        ]);
    }
}

My routes:

Route::get('/upload','UploadsController@getUpload');
Route::post('/upload','UploadsController@postUpload');
Route::get('/download',function (){
    return view('welcome');
});
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.367058 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO