Redirecting after fopen()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Redirecting after fopen()

Post by sirstrumalot »

Okay, so I have a form that POSTs to itself and uses fopen to create a csv named after the person and save it on the local machine. It all works fine and the file is rendered perfectly. My only problem, and i'm probably just dumb, is that when it's done, I can't get it to redirect via the header or via the form action to the next page. It just goes to itself and is blank. Any idea? Here's the code:

Code: Select all

<?php 
 
$f = addslashes($_POST['firstname']);
$m = addslashes($_POST['middlename']);
$l = addslashes($_POST['lastname']);
date_default_timezone_set ("America/Chicago");
$d = date("mdY-Hi");
$_SESSION['clinician'] = $f.$m.$l."_".$d;
 
session_start();
$first = addslashes($_POST['contact_first']);
$middle = addslashes($_POST['contact_middle']);
$last = addslashes($_POST['contact_last']);
$_SESSION['patient'] = $first.$middle.$last."_".$d;
 
 if(isset($_POST['Submit'])){
        $name = ''.$_POST['contact_first'].''.$_POST['contact_middle'].''.$_POST['contact_last'].''.date('mdY-Hi').'';
        $filename = "formfiles/".$name.".csv"; 
        $csv_output = '"'.$_POST['missed_aptDate'].'","'.$_POST['missed_aptTime'].'","'.$_POST['missed_aptTimeAMPM'].'","'.$_POST['missed_therapyType'].'","'.$_POST['missed_comments'].'"'; 
        
        $name = '"'.$_POST['contact_first'].''.$_POST['contact_middle'].''.$_POST['contact_last'].''.date('mdY-Hi').'"';
 
        $handle = fopen($filename, 'w+');
        fwrite($handle, $csv_output);
        fclose($handle); 
        exit;
        
        set_msg('Contact Updated');
        $redirect = "sigcapture/missedvisit/employee/capture.php";
        header('Location: '.$redirect); die;
} 
?>
Also, any shot in the dark there is a way to create and save the file on an absolute pathname relative to the OS? (i.e.

Code: Select all

$filename = "C:\formfiles\".$name.".csv";
) Something crazy like that? (just dreaming)
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Re: Redirecting after fopen()

Post by sirstrumalot »

Here's the resulted page after submitting the form. It's just blank.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content=BJSOTCAMKB name=SKYPE_FRAMEID></HEAD>
<BODY></BODY></HTML>
 
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Re: Redirecting after fopen()

Post by sirstrumalot »

LOL. It was the exit;
Nice.
Sorry to bother you.

ME -----> FAIL
Post Reply