简体   繁体   中英

Save a text file from PHP and AJAX

I have a file in the C: drive

'C:/myFile.txt'

I know the path and I simply want the user to save the file. However I try to use javascript

window.location.assign('C:/myFile.txt');

I get the path name not being understood.

I also try

window.open('C:/myFile.txt');

So I was thinking to send an AJAX request to PHP, supply the path, and use fopen. I do that and pretty much nothing happens. I need it to prompt as a download/save as.

If this server is remote to the user, they will not be able to download a file with a path from your C: drive in their browser.

You will need to place the file somewhere in your web root and then use its URL for downloading: window.location.assign('http://www.example.com/myFile.txt');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM