Creating Debug Output File

This will write / overwrite a file called test.txt in the local directory of the php file. You may need to create thr file first and enable write permissions for it to work. $data = “START-“.strftime(‘%c’).”-START”; $file = “test.txt”; $fp = fopen($file, “w”) or die(“Couldn’t open file for writing!”); fwrite($fp, $data) or die(“Couldn’t write values […]

Read More

echo a File

  Echo'ing the contents of a file //Get the url of a file and echo that file – this can be a remote web site file or a local one if (isset($_POST['url'])) { $url_string = $_POST['url']; $url_string = stripslashes(htmlentities(strip_tags($url_string))); echo file_get_contents("http://$url_string"); }      

Read More

Importing MySQL Table From An Uploaded CSV File

Loading A Table From An Uploaded .csv File <?php include_once('config.php'); //—– CONNECT TO DATABASE —– mysql_connect("localhost", $songs_db_username, $songs_db_password, $songs_db_name) or die("cannot connect"); mysql_select_db($songs_db_name) or die(mysql_error()); //Select the database so it doesn't need to be specified in mysql functions if ( (isset($_POST[‘action’])) && ($_POST[‘action’] == "uploading_all_songs_file") ) { //—————————————- //—– UPLOADING NEW ALL SONGS FILE —– […]

Read More

Paths

Up 1 parent directory level PHP Website Root directory This will give you the root directory of the current website (not the server root), e.g. ‘/public_html/’. If you want to access a folder above it you can do this: The current file Filesystem path – web server referenced Get filename from a path string

Read More

Read file

Read a text file Read a binary file to an array Your file may be byte based by PHP works to stop you operating at a raw byte level, so you have to workaround that a bit by using unpack If your file is very big then get clever with fread etc and only read chunks […]

Read More

Temporary File

Creating a temporary file //Create temporary file destination if (!is_dir('temp/')) { mkdir('temp', 0777, true); } $decrypted_filename = 'temp/' . uniqid(rand(), true) . '.txt'; //Use it… //Delete the file unlink($decrypted_filename);  

Read More