Tuesday, February 28, 2017

Laravel Corrupted Files - Files contain temporary path?

I'm currently developing a content management system using Laravel, however I am coming across a very strange issue...

//If an asset was provided
$asset = $request->file('asset');
if($asset) {
  //Set the file name.
  $fileName = $asset->getClientOriginalName();
  //If we could move the uplaoded asset.
  if(Storage::disk('local')->put('presentation_assets/'.$fileName, $asset)) {
    //Save the file name in the database.
    $presentation->asset = $fileName;
  }
}

The above code successfully uploads the file and places it into the directory, and then proceeds to save the filename in the database, however the file becomes corrupt.

When uploading a test.txt file, the upload succeeds, however when examined on the server, the file contents is changed to the temporary path (see below)?????

/tmp/phpkTe9NX

Can anyone shed some light onto why this would happen? I'm completely stumped!

Thanks for your help,

Alex




via Alex Mayo

Advertisement