Reputation: 1027
i have script like this in my view
<form method="post" enctype="multipart/form-data" action="{{ URL::route('import.produk.post') }}">
<input type="file" name="import">
<button class="btn btn-primary form-button" type="submit">Save</button>
</form>
in my controller i wanna show path of file
lets say that file located in D:\Data\product.xlsx
i using this script to do that
public function postImportProduk() {
$input = Input::file('import')->getRealPath();;
var_dump($input);
}
but it's not display real path of the input file instead temp file like this output
string(24) "C:\xampp\tmp\phpD745.tmp"
i try with ->getFilename()
it's show temp filename too phpD745.tmp
but if i'm using ->getClientOriginalName()
it's show exactly product.xlsx
i wonder how to get file real path
ps : i'm using laravel 4.2
Upvotes: 1
Views: 18718
Reputation: 21
Getting the original file path is not possible for security purposes.
Upvotes: 1
Reputation: 5939
After you do the upload, the file is stored in a temporary directory, with a randomly generated name.
Now that you have the file in your server, you want to move it to some specific folder that you have to designate. A simple example in your case would be this:
public function postImportProduk() {
$input = Input::file('import');
$destinationPath = '/uploads/'; // path to save to, has to exist and be writeable
$filename = $input->getClientOriginalName(); // original name that it was uploaded with
$input->move($destinationPath,$fileName); // moving the file to specified dir with the original name
}
Read more on the functionality here.
Upvotes: 2