0

I am developing this website where users can browse for a file, more specifically a .csv file on their computer (clientside). I then want to send the contents of this .csv file to my server. Once serverside, it will be stored into my database.

But firstly, I need to get the path of the .csv file. So i assume i should allow the user to browse for the file from their computer. Then when the user has chose a file, the path will be stored into a variable such that i can proceed on to store the contents to my database.

I therefore have 3 questions:

  1. How do I allow for the user to browse the file?
  2. How do I retrieve the path client side?
  3. How do I store the retrieved path client side?

Code snippets and references will be appreciated.

Bart
  • 19,692
  • 7
  • 68
  • 77
Lloydworth
  • 743
  • 6
  • 20
  • 38
  • one of the first hits for "html upload file" http://www.tizag.com/htmlT/htmlupload.php – puk Jan 12 '12 at 05:31
  • but how do i make the path of the file to be auto-stored into a variable? – Lloydworth Jan 12 '12 at 05:35
  • You meant client side right? Maybe you should rewrite the questions to make it easier to understand. Here, I'll edit it a little for you – puk Jan 12 '12 at 05:45
  • 1
    possible duplicate of [Quick php file upload guide](http://stackoverflow.com/questions/3696803/quick-php-file-upload-guide) – nikc.org Jan 12 '12 at 05:47
  • No worries if you can't accept this answer, but the w3schools site has a good example here: [http://www.w3schools.com/php/php_file_upload.asp](http://www.w3schools.com/php/php_file_upload.asp) – Tom Haws Jan 12 '12 at 05:33

2 Answers2

1

"path will be stored into a variable such that I can proceed on to store the contents to my database" - No, that's not how it works.

You're not storing a path. You're actually allowing the user to specify the path to the file in the browser. However, when the form is submitted, the actual contents of the file are read and posted to your server in the form post along with the rest of the form fields.

You can read the file server-side and continue to parse it in PHP and store it in the database etc.

Gaurav Gupta
  • 5,380
  • 2
  • 29
  • 36
0

There's a section in the manual dedicated to this topic. It should have all the information you need.

Jordan Running
  • 102,619
  • 17
  • 182
  • 182