Jump to content

Saving to local machine HOW?


venkir

Recommended Posts

Hi All:

This appears to be simple but I am stumped. I have searched through all the past post but to no avail. Basically:

1. User clicks on a link and a php page is presented.
2. User selects a local TEXT CSV file and clicks on the 'Upload File' button.
3. Local file is sent to the web browser, where each line in the CSV file is read, processed, geocoded.
4. A HTML table is formed to display the results of the geo coding.

Everything works until this step.

5. The user needs to now click on a button, type in the name for the output file (just the name ....)
and the code should use the old directory path, append the output file name (as entered above), append the extension ".csv", open the file, write to it and close the file.

I know all about fopen, fwrite and fclose. My specific questions are:
1. How do I parse and retain the directory path of the original csv file so that I can save back to the same dir? $_FILES['userfile']['name'] does not have the dir path.
2. In the php file which displays the result, how do I create another button that will enabe the user to traverse the local file system pick another location and type in the file name for the output?
3. Lastly, since the results are displayed in the browser, the data has already been sent to the browser. If I save the results in an array in the php that processes the input, after the user clicks on this button, is the array available to me to then traverse and fwrite to the file?

I guess fundamnetally I don't understand where the data resides since I don;t want it to go back to the web server just to save the ouput to a local file.

Any help will be much appreciated!!!!
-Venki
Link to comment
Share on other sites

Thanks, Worked beautifully, wonder why the PHP Cookbook did not have any examples of this neither did the PHP and MySQL web development book. Anyway that justifies the existance of this forum. I have two additonal questions:

To explain better, the current process is:
1. getfile.php: Gets the original input file by using a form and a submit button, calls processfile.php
2. File gets uploaded to web server successfully, invokes processfile.php which
--moves the uploaded file,
--process each record
--Forms a table to display results in html
--and creates two ouput files in the web server one with .xml and one with .csv extension
3. I put the force download snippet of code before the html display in this php.

But I don't see the results on the screen. When I click on the 'Submit' button in the getfile.php, it waits (processing ...) and then the pop-up window to save the first xml file comes up. File is saved successfully, but .......

1. The second csv file is not downloaded.
2. The html display does not show up now. Why and how to fix it?

Thanks again for all the wonderful people out there.....This is one site that I am definitely going to contribute to.

-Venki
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.