Tutorials

Today you will learn how to upload files to your website. What types of files can you upload? You can upload anything. Although it is highly recommended you filter your results with size and type to prevent unauthorized files. You should be careful with executable files as those could contain viruses and other malware.

Posted by in PHP

Today you will learn how to use PHP to load files from a folder. If you have something like a bunch of images or documents in a folder that you just want to throw up on the page, this becomes really handy. How do I open a folder and loop files? // select folder $docs_directory = "folder"; // open folder $dir_handle = opendir($docs_directory) or die("There is an error with your folder"); // loop through files while ($file = readdir($dir_handle)){ echo 'File: '.

Posted by in PHP

In a previous tutorial, we learned about hashing strings. Hashing works very well for strings like passwords where you don't need the data back in plain text. But what if you needed a way to get it back in the original format for things like credit card numbers? Remember that hashing is a one way street and there is no way to revert it back; so we use something else: encryption.

Posted by in PHP

Today you will learn how to use PHP to write text to another file. This is very useful if you want to keep a log file on your site. How do I write a file? If there is no file currently there, a new file will be created. // location and name of the log file $logfile = 'log.txt'; // open the log file $log = fopen($logfile, 'w') or die('Error opening log file.

Posted by in PHP

Today you will learn how to display the contents of another file. How do I display a file? One simple line will do the trick. echo file_get_contents("file.txt"); What files can I read? Pretty much any plain text file. HTML, TXT and PHP will work fine. Does this process code? The server won't process the code but your browser will.

Posted by in PHP