0

i am facing a problem in which uploading a file suspends after a while (for files with large size(20M+)). It works on smaller files as expected. I really don't know the reason for this. here is my view which contains the uploading method(using simpleUpload plugin ):

<html>
   <head>
    <meta name="csrf-token" content="{{ csrf_token() }}">
      <title>upload</title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src="/js/xhr2.js"></script>


      <script type="text/javascript">
         $(function(){
               $('#upload').on("click",function(){
                     $.ajaxSetup({
                         headers: {
                         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                         }
                     });
                     $("#file").upload("localhost:8000/upload",function(data){
                      console.log(data);
                     },$("#prog"));
               });
         });

      </script>
   </head>
   <body>

    <input type="file" id="file" name="file">

    <input type="button" id="upload" value="upload">
    <br>
    <progress value="100" max="100" min="0" id="prog" style="display: block;width:400px">

   </body>

</html>

and here is my controller:

<?php
namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class UploadsController extends Controller
{
    public function getUpload(){
        return view('upload');
    }
    public function postUpload(request $request){
//        dd(\request()->all());
        $time = Carbon::now();
        if ($request->hasFile('file')) {
            $file = $request->file('file');

            $extension = $file->getClientOriginalExtension();

            $upload_success = $file->storeAs('public',$file->getClientOriginalName());

            if ($upload_success) {

                return response()->json($upload_success, 200);
            }

            else {
                return response()->json('error', 400);
            }
        }
        return response()->json('no file to upload', 400);


    }

}

and finally my routes:

Route::get('/upload','UploadsController@getUpload');
Route::post('/upload','UploadsController@postUpload');

Thanks for your help.

Khaled Rimawi
  • 115
  • 1
  • 6
  • It sounds like its just timing out. Take a look at this, you might just need to up your settings in your php.ini file. https://stackoverflow.com/questions/578190/can-file-uploads-time-out-in-php – Webtect Mar 05 '18 at 22:34
  • i modified the following upload-max-filesize max-input-time post-max-size memory-limit but the problem still hold – Khaled Rimawi Mar 05 '18 at 23:11
  • What about max_execution_time. This is the only other setting I can think of that might hinder the upload. You did a phpinfo() after this to make sure the settings took right? Sometimes you need to restart apache. – Webtect Mar 06 '18 at 02:37
  • Thank you very much, i changed max_execution_time and it seems that it worked. – Khaled Rimawi Mar 06 '18 at 07:52
  • Update:the problem still hold. – Khaled Rimawi Mar 06 '18 at 10:14
  • Are you getting any errors? Check your logs to see what its saying and let me know what it says. If it says nothing chances are its just timing out which points to config settings. Does it work fine with smaller files? What size is it stopping at? Have you timed the upload to see when it stops, my guess is 30 seconds ( usually the default ). Let me know on the above and I will try to help further. – Webtect Mar 06 '18 at 13:24
  • for smaller files it just works fine. I think it's a time issue because it always stops when the time for the upload precedes 5 minutes. Do you think it's browser time out? or it might be a server time out ? should i figure out a way to send the file as chunks instead of one piece ? Thank you. – Khaled Rimawi Mar 06 '18 at 16:54
  • Take a look at this, https://stackoverflow.com/questions/36600197/how-to-upload-large-file-5mb-in-laravel-5 Maybe try streams? Hopefully the version of Laravel your using works with this, otherwise I came across this as well. https://github.com/jildertmiedema/laravel-plupload but you might want to research the second option. – Webtect Mar 06 '18 at 20:24
  • do you have an idea of what should i do in front end in order to stream the file also ? – Khaled Rimawi Mar 08 '18 at 12:11

0 Answers0