PHP personal websites establish a series of lectures (4) 3 homepage news releases, making it easier for you to update (2)
----- In the previous lecture, we have implemented the basic functions of homepage news publishing. In this lecture, we will add more bricks and tiles to make it more powerful. (An easy-to-use software, in fact, is the addition of a batch of ancillary functions of basic functions. these ancillary functions are also easy to figure)
----- First, let's clarify what convenience we want. We don't want to forget to delete things that we did a few days ago. The results are also published on the homepage as news (shame! ^ & ^ ). If we embed a piece of code in the basic implementation, such as using filectime ($ filename), then in UNIX, we can get the time from January 1, January 1, 1970 to the time when the last File was modified (the date and time when the file was generated in WINDOWS ), from January 1, January 1, 1970 to the current number of seconds, you can use $ mynow = mktime () to get, subtract, and Judge. IF> the expected time, Hey, Sorry, unlink ($ newspath. $ filename )...... What ?! Where should I put this code? What do you mean.
Maybe you are not always surfing the Internet on a machine. what should you do if you get a new news but are not on your computer? The most ideal thing is to upload files on the home page. You may have a page (Admin ?) You must use a password to access the website. (if you still cherish your website, this is necessary. you 'd better not let others know the file name ). The following code uploads a file that is everywhere:
If (isset ($ upfile ))
{
?>
The information of uploaded files is as follows:
File storage path:
Original file name:
File size (in bytes ):
File type:
}
Else
{
?>
News uploading
}
?>
----- Here we see a combination of PHP and HTML for reference. Although it is convenient to upload files, it always gives a sense of insecurity. Once leaked, the system security of your server is threatened, because the uploaded files may be some destructive execution files (that is, viruses or hacker programs) it is safe to write an online edited file. The following is an example:
<〈? Php
Function mywritefile ($ filename, $ contents ){
If ($ fp = fopen ($ filename, "w ")){
Fwrite ($ fp, strpslashes ($ contents ));
Fclose ($ fp );
Return 1;
}
Else {return 0 ;};
};
// Judge the variables returned by the form
If ($ submitButton = "finished "){
$ Rs = mywritefile ("$ page", "$ test ");
Echo "$ page
";
}
Elseif ($ action = "page") // when the variable action value is "page"
{$ Contents = "$ page ";
$ Fp = @ fopen ($ content, "w +") or die ('could not open file! ');
$ Contents = htmlspecialchars ($ contents );
Fclose ($ fp );
Echo "";
}
Else
{Echo "";
}
?>
----- Now, the implementation of homepage news publishing has come to an end. We can find that any powerful statement is composed of some simple functions. The third part of the entire functional improvement process uses the method of superposition enhancement, and the software engineering top-down, layer-by-layer analysis development method is different. This is a method suitable for learning. it is quite useful to write your own exercises.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.