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

Write File

Write text to a file $output_text = "Hello"; file_put_contents("files/output_filename.txt", $output_text); //(Will overwrite an existing file) Note that the directory you write the file to will need chomd set to 777 (php needs the X bit set to be able to write).  This can be a potential security risk if this is a concern.

Read More

Read file

Read a text file if (is_file('some_filename.json')) { $file_contents = file_get_contents('some_filename.json'); } 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 $filename = "myfile.bin"; if (is_file($filename)) { $handle = fopen($filename, […]

Read More

Paths

  Up 1 parent directory level <link href="../styles.css" rel="stylesheet" type="text/css" /> <?php require('../header.php');?>    

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

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

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