-2

I have PHP script. I enter sitename in text field, click ENTER and get website metadata (keyword, description). It is working fine. But now I want that user is able to save these metadata to file and save file to own PC. I know that I should use HEADER. But I am newbie in programming and don't have ideas how to do that. Could you help me please with code?

Alex Alex
  • 1
  • 3
  • 2
    Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). You should include at least an outline (but preferably a [mcve]) of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Mar 08 '18 at 11:36
  • I don't have code for downloading file. What should I do? I thought somebody can help me here or at least give me right direction what to read – Alex Alex Mar 08 '18 at 11:40
  • At least show your current PHP script. – Mikhail Aksenov Mar 08 '18 at 11:51
  • Is that your solution? https://stackoverflow.com/questions/8485886/force-file-download-with-php-using-header – Mikhail Aksenov Mar 08 '18 at 11:52

1 Answers1

0

First you need to write this metadata in a text file and save it on your server. Now give link to that file in your website.

<a href="linktofile on your server" >Download File Here</a>

when user will click on link it will be automatically downloaded on their PC.

you can use following example to create a file on your server and write to it.

https://davidwalsh.name/basic-php-file-handling-create-open-read-write-append-close-delete

Thanks.

SRK
  • 3,476
  • 1
  • 9
  • 23
  • 1
    "_it will be automatically downloaded on their PC_" Not quite true, users could have a setup to show it directly in their browser. You could add the HTML5 attribute `download`. – brombeer Mar 08 '18 at 11:56
  • Thank you. Why do I need to save file to my server? I just need to allow user download it on his PC. – Alex Alex Mar 08 '18 at 11:57
  • In order to download any file it must exist somewhere right? So first you need to create the file and then user can download that file. That is the reason you need to save that file on your server and provide them a link to download the file. – SRK Mar 08 '18 at 12:04
  • @kerbholz yes you are right. But they can save the file from there too if they want to. :) – SRK Mar 08 '18 at 12:06