Dan_Mason Posted March 24, 2009 Share Posted March 24, 2009 Help! I asked about this a while ago, but i didnt word it very well, as i wasnt sure exactly what i was looking for. Basically, I am using the fopen() function to write a .txt file, but i want the user to be able to specify the path that the file saves to. I need to do this as some of our clients are restricted and arent even allowed to save files on the C Drive of their Computers! (Paranoid Network Admin...) I wanted to do this using a File Browser within the Web browser, so that when the user selects the Directory needed, the path is written to the variable which is then passed into fopen(). <?php $filename = $DirectoryUserHasChosen //$filename = $FilePath; $somecontent = "Recorded Sections\tNumber Of Coils\etc\etc"; fopen($filename, 'w'); etc etc Rest of code ?> Any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 24, 2009 Share Posted March 24, 2009 Are you wanting to write the file to the server or to the user's computer. If you want the user to save to the server you would want to build a PHP based file browser (I have a script on my PC at home, but you should be able to find something on the web). If you want to save the file to the user's PC it will not be straitforward. The user can't select "C:\directory\" to save on their PC because the server is the one doing the writing. The user would have to indicate the path to the directory on their machine from the server assuming the server even has access to the user's PC. Something like "\\users_pc\sharename\directory\". I suspect you *may* be able use a PHP file browser that can navigate network shares, but I've never needed to do that. Quote Link to comment Share on other sites More sharing options...
Dan_Mason Posted March 24, 2009 Author Share Posted March 24, 2009 Well its basically A Report that The server generates for the client. Then each day when the report is sent to them (by Hyperlink), They click on the Download Summary Data Button To get the .txt file. Is there no way of being able to specify a directory from the client side? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 24, 2009 Share Posted March 24, 2009 OK, your last response doesn't fit with your first post. What exactly are you wanting to do. You state in the last post that you are creating a link for the user to get the report. Is the problem that the reprot opens in the browser instead of saving to the user's machine? In that case you need to add the required headers to "force download" so the file will not automatically open in the user's browser. However, if you want the PHP script to automatically write the file to the user's PC, then as I said before that is not possible without the server being able to access the user's PC through a network share and the user specifying the path to that share from the server. If you are only wanting to provide the txt for the user to download to their machine, then you don't even need to write the file to the server (if you don't need to save it). Just "build" the file in your PHP script and serve it to the user to download. Here's a short example: //Create code to generate the report content as a variable $content = "Report info"; header("Content-Type: text/html"); header("Content-Disposition: attachment; filename='name.txt'"); echo $content; If you created that as a page and pointed your browser to it you would be prompted to download the file 'name.txt' which willhave the text 'Report info'. Quote Link to comment Share on other sites More sharing options...
Dan_Mason Posted March 25, 2009 Author Share Posted March 25, 2009 Hello Again, Sorry, I'm not making myself completely clear (Quite new to this!). Here is a screenshot of the Report that is sent to the User. The "Export" button on this page is a link to the file with the fopen function in it. That file is the one Writing the .txt file. The .txt File Contains All of the Summary Data From the report shown above. What I would like to happen is that when the user clicks the "Export" Button, a "Save As" box appears, so that the user can specify Where to save the file. I hope this makes it more clear :S Thanks Anyway For Helping Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 25, 2009 Share Posted March 25, 2009 Yes, that is one of the scenarios I described above. But, you need to make a decision.. When the user selects the Export button do you want to create a physical file on the server before serving it to the user OR do you want to create a "virtual" file each time the user creates a report and send that to the user. If you do not need to keep copies of the reports (on the server) for historical purposes then you should NOT create physical files on the server. The small snippet of code I posted above will do exactly what you are asking. Assume that code is the page that is called when the user selects the Export button. Just replace this line $content = "Report info"; with all of the code you now use to generate the report file (just assign the report content to the variable). If you still don't understand, post the code you have for the page that is called when the Export button is called and I'll give more specific details. Quote Link to comment Share on other sites More sharing options...
Dan_Mason Posted March 25, 2009 Author Share Posted March 25, 2009 Thankyou so much man! My Boss Is Especially Pleased With Me Now! Sorry about the misunderstanding, You know how it is, You know exactly what you want, but putting it across to someone who doesnt know what you want is quite difficult lol It all works peachy now anyway, so cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.