i have form file uplaod. works find. don't want move file directly folder. after submit show confirm page , there show uploaded file with
header('content-type: image/x-png'); $file = file_get_contents(\illuminate\support\facades\input::file('restimg')); $imgtype = \illuminate\support\facades\input::file('restimg')->guessclientextension(); echo sprintf('<img src="data:image/png;base64,%s" style="max-height: 200px"/>', base64_encode($file));
this works fine. after confirmation move file folder. how can move file after confirmation? input::get('file') not available anymore.
you have store file in initial upload somewhere temporarily other default tmp
directory.
the documentation php file uploads says:
the file deleted temporary directory @ end of request if has not been moved away or renamed
this means moving onto next request, file no longer available.
instead, move own custom temp directory or rename special, keep filename in $_session
persist next request.
for laravel, should mean putting in /storage
directory this:
// uploaded file $file = app('request')->file('myfile'); // build new destination $destination = storage_path() . directory_separator . 'myfolder'; // make semi-random file name try avoid conflicts (you can tweak this) $extension = $file->getclientoriginalextension(); $newfilename = md5($file->getclientoriginalname() . microtime()).'.'.$extension; // move tmp file new destination app('request')->file('myfile')->move($destination, $newfilename); // remember last uploaded file path @ new destination app('session')->put('uploaded_file', $destination.directory_separator.$newfilename);
just remember unlink()
file after second request or else it, or folder fill fast.
additional reference: http://api.symfony.com/2.7/symfony/component/httpfoundation/file/uploadedfile.html
Comments
Post a Comment