Beispiel #1
0
/**
 * creates a temp file and outputs it to the browser (script will die).
 * The file will be deleted after being transfered to the client.
 * @param string|array $file_content
 * @param string $file_name file name with extension
 * @param boolean $new_window Only works within AJAX calls
 */
function P4A_Output_File($file_content, $file_name, $new_window = false)
{
    $name = '_p4a_' . uniqid() . '_' . $file_name;
    while (file_exists(P4A_UPLOADS_TMP_DIR . "/{$name}")) {
        $name = '_p4a_' . uniqid() . '_' . $file_name;
    }
    $fp = fopen(P4A_UPLOADS_TMP_DIR . "/{$name}", 'w');
    if (is_array($file_content)) {
        foreach ($file_content as $line) {
            fwrite($fp, $line);
        }
    } else {
        fwrite($fp, $file_content);
    }
    fclose($fp);
    P4A_Redirect_To_File(P4A_UPLOADS_TMP_NAME . "/{$name}", $new_window);
}
Beispiel #2
0
 /**
  * Action handler for file download
  */
 public function fileDownloadOnClick()
 {
     P4A_Redirect_To_File($this->getNewValue(1));
 }