2016-07-21 7 views
0

私はuplaodへのファイルを持つフォームを持っています。すべての作品が見つかります。しかし、私はファイルを直接フォルダに移動したくありません。 は後に、私は確認ページを表示提出し、そこに私はPHP/Laravelで確認した後にtempからファイルを取得

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)); 

これは正常に動作してアップロードされたファイルを表示します。確認の後、私はファイルをフォルダに移動するのが好きです。確認後にファイルを移動するにはどうすればよいですか? Input :: get( 'file')はもう利用できません。

答えて

0

デフォルトのtmpディレクトリ以外の一時的なアップロードでファイルを保存する必要があります。

PHP file uploadsのドキュメントは言う:これが動いていることを意味遠ざけたり

と改名されていない場合

ファイルは、リクエストの終了時に一時ディレクトリから削除されます次の要求にファイルが使用できなくなります。

代わりに、独自のカスタムtempディレクトリに移動するか、特別な名前に変更してから、ファイル名を$_SESSIONのままにして次の要求に保持してください。

// Get the uploaded file 
$file = app('request')->file('myfile'); 

// Build the new destination 
$destination = storage_path() . DIRECTORY_SEPARATOR . 'myfolder'; 

// Make a semi-random file name to try to avoid conflicts (you can tweak this) 
$extension = $file->getClientOriginalExtension(); 
$newFilename = md5($file->getClientOriginalName() . microtime()).'.'.$extension; 

// Move the tmp file to new destination 
app('request')->file('myfile')->move($destination, $newFilename); 

// Remember the last uploaded file path at new destination 
app('session')->put('uploaded_file', $destination.DIRECTORY_SEPARATOR.$newFilename); 

ちょうど2番目の要求後unlink()にファイルを覚えているか、それに何かを行う、またはそのフォルダがいっぱいになります:

はLaravelの場合、これはこのようなもので/storageディレクトリにそれを置くことを意味する必要があります速い。

追加リファレンス: http://api.symfony.com/2.7/Symfony/Component/HttpFoundation/File/UploadedFile.html

関連する問題