1

At the moment, my application is stored on a Linux server (I do not have control of the server, so server adjustments are out of the question).

In my application there is a form where users can upload excel and CSV files, the request is then being passed into a Laravel validation request as shown below.

Whenever I try to upload the file, it claims the file is not there.

Laravel Request

public function rules()
{
    return [
        'user-file' => 'required|mimes:csv,xslx',
    ];
}

I've already figured out my problem, its that the default temp folder stores and then instantly delete the file so that the request cant find the file, so that by the time the above code runs, the file is no longer there and just returns an error.

How would I change the folder where the files are stored and point to there inside of a request?

Something like

public function rules()
{
 $name = 'user-file' .'.'. $this->file('user-file')->getClientOriginalExtension();
 $move = $this->file('user-file')->storeAs('/newdirectory',$name);
 return [
    //Point to the new file inside 'newdirectory' for the below request validation
    'user_file' => 'required|mimes:csv,xslx',
 ];
}
S_R
  • 1,818
  • 4
  • 27
  • 63
  • It seems like a really bad idea to me to create temporary files in a separate folder that isn't a tmp folder, because then they wouldn't automatically get cleaned up and pile up. You can't directly stream the file into memory from the upload and process it on the go? – G_V Feb 01 '18 at 09:12
  • Its looking like my only option because the default temp folder will not work properly. Its deleting the files far to quickly so that everything errors out before I can validate it. – S_R Feb 01 '18 at 09:20
  • You do have rights on the server to create temp files in the folder? That doesn't sound like normal behavior. Usually tmp folders get cleared at set intervals or after a period of time per file. Immediate removal seems rather pointless, so I'd reckon the tmp files never get created to begin with and that's why they aren't found. – G_V Feb 01 '18 at 10:00
  • The tmp files do get created, because when i check the modified status of the folder it changes to when i try to upload, to show the file has been inserted but then removed instantly. Also its not that I don't have rights on the server, its that a lot of other applications are stored on it, so changing server settings or php.ini files its really an option – S_R Feb 01 '18 at 10:24
  • In Linux, applications are effectively users too so you should be able to specifically change settings for one application's rights with chmod iirc, but yeah if that application is php then I see your problem. Maybe you can post this on the linux stack exchange too, see if there's something you can do with your settings to prevent this deletion before you are done with the file? Maybe there's some sort of flag on the temp file you can set to signal the file is still not processed. – G_V Feb 01 '18 at 10:33

0 Answers0