Home  >  Article  >  Backend Development  >  About the problem of generating text in php_PHP tutorial

About the problem of generating text in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:51:151052browse



Question
About the problem of generating text in php
Solution
Hello everyone, I have a problem

I have uploaded some data now, such as my personal information, etc. Then I want to add a "Download" button in the front desk. After clicking this button, the text I uploaded will be automatically generated from the server, and then downloaded and saved locally!

Does anyone know if there is any good way? It would be nice to give some tips, I have no clue now, I just learned programming not long ago!

Thank you!


Reference answer
.. What data did you upload? . bmp? php?
Reference answer
It's text! For example, a text like news, including title, date, content, etc. Is there any way?
Reference answer
The understanding ability is not very good. . I don’t understand what you are saying
Reference answer
This should be very simple, fopen---fwrite---fclose, you can refer to the text file writing code in the basic textbook.
Reference answer
I seem to know what you are going to do



//note: The directory where the file is located

$fileDir = './mydata';



//note: Check whether the directory is readable

if(!is_readable($fileDir)) {

die('Insufficient permissions');

}



//note: file initial array

$fileData = array();



//note:Read file

$handler = fopen($fileDir);

while(($filename = readdir($handler)) != FALSE){

if(!in_array($filename, array('.','..'), TRUE)) {

$fileData[]=file_get_contents($filename);

}

}



//note: For the operations you need, just use the $fileData array directly


Copy the code, I don’t know if it’s what you want
Reference answer
I haven't tried your code, but it doesn't look very good
Downloading a file does not require you to list the files in all directories and put them into an array

Owner, what do you need and how to download it?
How to display downloads in the frontend
If you want to directly display the path plus the file name, $filename = 'xiaoasp.txt'; //I'm testing here locally, you can use variables to get the file name using GET

Header("Content-type: application/force-download"); //Because txt files are parsed by the browser by default, they are forced to be downloaded

readfile($filename); //Then the output file

exit;


Copy code
Reference answer
Actually my idea is very simple, I just think:

On the background page, the news is uploaded to the server in the form of "title, date, author and content".
The fields on the server are id title date author content

In this way, I can watch my uploaded news in the front desk. This can be easily achieved using php.

But I suddenly thought about adding a "download" button in my background. The effect it wants to achieve is: after clicking, it will automatically upload all the news I uploaded to the server within a month (default) in the form of text or word Save it locally, so that I can read the news I uploaded before without going online in the future. Do you understand?

Of course, this is just an example, don't ask me why I don't save and then upload the news! Haha
Reference answer
Word format? It’s not that simple. Search the Internet for a PHP class that generates Word format files.
Reference answer
Text is fine, anything is fine, what I want is to be able to download it!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632582.htmlTechArticle Question about the solution to the problem of generating text in php Hello everyone, I have a problem. I have uploaded the data now. For example, I Personal information, etc. Then I want to add a "next...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn