1

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

Neversaysblack
  • 875
  • 3
  • 16
  • 36

2 Answers2

2

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.

Andrius
  • 5,568
  • 17
  • 27
  • so it's not possible to know where original path of file...i want to save both original path and destination path to database.... – Neversaysblack Nov 18 '15 at 08:20
  • What do you mean "original path"? If you want to know where the user is storing the file in his computer then no, it is not possible and would be a security issue if it was. – Andrius Nov 18 '15 at 08:21
1

Getting the original file path is not possible for security purposes.

See More How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?

Community
  • 1
  • 1
EvelynRose
  • 21
  • 5