Link to home
Create AccountLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

Upload CSV from website folder

I have a site that I upload csv files to the DB, when I click my search button, it automatically opens my computer.  How do I set it to open up a folder on my website, or my computer?
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

You need to use php to manage the file upload http://www.w3schools.com/php/php_file_upload.asp plus you have to remember to make the folder where the files go writeable.
Avatar of Robert Granlund

ASKER

NO, I want to upload a file from a website folder.  NOT upload TO a website folder.
Do you mean that you want to download a file from the server to your computer?
No I want to upload a file into a MySql DB from a Website folder.  I need to know how to write my form so it opens up a website folder instead of my computer.
Please take some time to think about exactly what you need because this is confusing. Maybe make some bullet points of what you do and what you are missing.
1) You have a csv file on your LOCAL computer

2) You click a button on the website that finds the CSV file on the LOCAL server and selects the file.

3) You click another button that uploads the CSV file to your SERVER in Folder mysite.com/save/

4) How do I get the CSV file imported to my DATABASE.

What does this mean?  "I need to know how to write my form so it opens up a website folder instead of my computer."
@Padas and @Ray (From Above)

This is what I need:

2) You click a button on the website that finds the CSV file on a website folder and selects the file.

for example it opens the folder: www.MYSITE.com/CSVFOLDERS/
and I can choose a file from there.
It's not too difficult to write a PHP page that will list files in a directory.  What do you think will happen when you select the file?  And how do you think that will happen?
want to upload a file into a MySql DB from a Website folder
OK, how did it get into that folder?  Where did it come from?
The CSV file has been sent via FTP to a specific website folder by PersonA.  At a later date PersonB after reviewing the CSV will want to upload it into a MySQL DB.

So with: <form name="input_table" method="POST" action="index.php" enctype="multipart/form-data">

<input type='file' name='filename'/>

How do I get input type='file' to open a web folder instead of my computer?
If it is bulk data, what you will do with your form is simply post something like, "ok_to_import"="yes" and then us a php script to import your data.  if it is one off data (one row of data) you could use the csv file to populate your form, then submit it.  

Maybe post your data layout in your db and sample csv data.
How do I get input type='file' to open a web folder instead of...
I don't think you can do that.  Think about it.  If you could prepopulate the value in an input of type=file you could copy data from any computer that visited your site, without the client's knowledge or permission.

Does PersonB simply review the CSV or does PersonB make changes to the CSV?

Why not just have a script that only PersonB can run.  It can copy the CSV into the data base.  This does not have to go through any HTML form.
How do I get input type='file' to open a web folder instead of my computer?

You can't.  That form is specifically for uploading a file from a client computer, not the server.  You can read a file from the server into a PHP variable and use one of the CSV-to-MySQL scripts to put it in the database.
Basically I need this:
ALLOW THE IMPORT ROUTINE TO USE A FILE FROM THE SERVER
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Could you do some thing like:
$handle = fopen($_FILES['http://www.MYSITE.com/FOLDER/MYCSV.csv']['tmp_name'], "r");


????????
Why?  What is the connection to ['tmp_name']?  That is usually something that comes from a file upload.  Why not move the file to a permanent location so you can use it after the request completes?