PHP file functions

fopen
  
Opens a file for reading and/or writing. This file can be stored on the server's hard disk, or PHP can load it from a URL just like a Web browser would.
fclose
  
Tells PHP you're finished reading/writing a particular file and releases it for other programs or scripts to use.
fread
  
Reads data from a file into a PHP variable. Allows you to specify how much information (i.e. how many characters or bytes) to read.
fwrite
  
Writes data from a PHP variable into a file.
copy
  
Performs a run-of-the-mill file copy operation.
unlink
  
Deletes a file from the hard disk.

Through examination of server logs, you'll probably find that this is one of the most requested pages on your site. If you ask yourself some of the questions above, you'll realize that this page doesn't have to be dynamically generated for every request. As long as it's updated every time new content is added to your site, it'll be as dynamic as it needs to be. With a PHP script, you can generate a static snapshot of the dynamic page's output and put this snapshot online, in place of the dynamic version .

By converting high-traffic dynamic pages into semi-dynamic equivalents, which are static pages that get dynamically regenerated at regular intervals to freshen their content, you can go a long way towards reducing the toll that the database-driven components of your site take on your Web server's performance.

Website, you probably see site traffic as something you'd like to encourage. Unfortunately, high site traffic is just the kind of thing that a Web server administrator dreads—especially when that site is primarily composed of dynamically generated, database-driven pages. Such pages take a great deal more horsepower from the computer that runs the Web server software than plain, old HTML files do, because every page request is like a miniature program that runs on that computer.

  • Ensure that non-conflicting file names are generated.
  • Synchronize stored files with the database by adding an entry for each file as it is uploaded.
  • Delete old files when their database entries are deleted.