Skip to content

Instantly share code, notes, and snippets.

@luckyshot
Created April 16, 2013 12:46
Show Gist options
  • Save luckyshot/5395619 to your computer and use it in GitHub Desktop.
Save luckyshot/5395619 to your computer and use it in GitHub Desktop.
PHP Working with files
<?php
// Downloading a file
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=".date('Ymd-His ').$this->query.".csv");
header("Pragma: no-cache");
header("Expires: 0");
// Check if file exists
if (file_exists(strtolower($filename).'.'.$this->extension)) {}
// Save file
$filehandle = fopen($filename, 'w') or die("Error");
$fwrite = fwrite($filehandle, $text);
fclose($filehandle);
// Delete file
unlink($this->filename);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment