URL variable from text file

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
tchavez
Forum Newbie
Posts: 6
Joined: Mon Mar 30, 2009 12:57 am

URL variable from text file

Post by tchavez »

Is there a way to read the content of a text into a url variable?

Ex: Read "This is the information." from file info.txt

So I would have a variable $a = the line read from the text file.

URL would be header( 'Location: http://somehost.com/test.php?parm1='.$a);


Here is what I tried:

$source = "info.txt";
$a = file_get_contents($source);
header( 'Location: http://somehost.com/test.php?parm1='.$a);

But it doesnt seem to pass anything in the variable. Reason for needing to do this is I have PHP write the file info.txt after files are uploaded (file contains a list of the files that were just uploaded), I then need to pass that list to another page for sending an email confirmation of what files were uploaded.

Thanks in advance,
T.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: URL variable from text file

Post by requinix »

Code: Select all

$source = "info.txt";
$a = file_get_contents($source);
header( 'Location: http://somehost.com/test.php?parm1='.$a);
Looks fine (though you should pass $a through urlencode before using it in the redirection). What does test.php look like?
tchavez
Forum Newbie
Posts: 6
Joined: Mon Mar 30, 2009 12:57 am

Re: URL variable from text file

Post by tchavez »

test.php
<?
$Name = "Me";
$email = "me@host.com";
$recipient = $_GET['email'];
$mail_body = "Your file(s) have been successfully uploaded to the Dev file server, if you need any further assistance please email me@host.com or call 111.222.3333."."\r\n";
$mail_body .= "Files that were uploaded:"." ".$_GET['a'];
$subject = "Files have been uploaded";
$header = "From: ". $Name . " <" . $email . ">\r\n";
ini_set('sendmail_from', 'me@host.com');
mail($recipient, $subject, $mail_body, $header);

//Below sends My copy of upload complete mailer.

$Name2 = "Me";
$email2 = "me@host.com";
$recipient2 = ""me@host.com";
$message = "Name: " . $_GET['name'] ."\r\n";
$message .= "Email: " . $_GET['email'] ."\r\n";
$message .= "Phone: " . $_GET['phone'] ."\r\n";
$message .= "Due Date: " . $_GET['duedate']."\r\n";
$subject2 = "Files have been uploaded";
$header2 = "From: ". $Name . " <" . $email . ">\r\n";
ini_set('sendmail_from', 'me@host.com');
mail($recipient2, $subject2, $message, $header2);
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: URL variable from text file

Post by requinix »

I see a lot of $_GETs in there, but nothing in the URL you posted. According to that, the only variable in the URL is $_GET["parm1"] (which you don't use).
tchavez
Forum Newbie
Posts: 6
Joined: Mon Mar 30, 2009 12:57 am

Re: URL variable from text file

Post by tchavez »

header( 'Location: http://www.host.com/test.php?name='.$_POST['name'].'&email='.$_POST['email'].'&phone='.$_POST['phone'].'&duedate='.$_POST['duedate'].'&parm1='.$a) ;

This is the actual redirect I has set the other one up just for testing. I filled in the other variables hardcoded.
tchavez
Forum Newbie
Posts: 6
Joined: Mon Mar 30, 2009 12:57 am

Re: URL variable from text file

Post by tchavez »

Here is the full code for the page that sends to the test.php.

Code: Select all

 
<?
        if ($_FILES['Filedata']['tmp_name'] && $_FILES['Filedata']['name'])
    {       
       $uploadfile = "uploads/".$_POST['name']." ".date('m-d-y')."/uploads.txt";
    $fh = fopen($uploadfile, 'a+') or die("can't open file");
    $stringData = $_FILES['Filedata']['name']."\n";
    fwrite($fh, $stringData);
        //#-- upload the image to the volume folder
        $vSourceFile = $_FILES['Filedata']['tmp_name'];
        $vImageName = stripslashes($_FILES['Filedata']['name']);
        $vFoldername = 'uploads/'.$_POST['name']." ".date('m-d-y')."/";
        if(!is_dir($vFoldername))
        {
            mkdir($vFoldername, 0777); //#-- Create a new session directory
            chmod($vFoldername, 0777); //#-- Set all the access permissions to the folder
        }       
        if(copy($vSourceFile,$vFoldername.$vImageName))
        
            $vStatus = 1;
        else
            $vStatus = 0;
    }       
    else
    {
        $vStatus = 0;
    }
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    if($vStatus)
        echo '<status>1</status>';
    else
        echo '<status>0</status>';
        
    //Writes instructions files from form data
    $ourFileName = uploads/".$_POST['name']." ".date('m-d-y')."/".$_POST['name']."-".date('m-d-y H.i.s').".txt";
    $fh = fopen($ourFileName, 'w') or die("can't open file");
    $stringData = $_POST['name']."\n";
    fwrite($fh, $stringData);
    $stringData = $_POST['phone']."\n";
    fwrite($fh, $stringData);
    $stringData = 'Due on: '.$_POST['duedate']."\n";
    fwrite($fh, $stringData);
    $stringData = $_POST['email']."\n\n";
    fwrite($fh, $stringData);
    $stringData = $_POST['details']."\n\n";
    fwrite($fh, $stringData);
    $source = "uploads.txt";
    $html = file_get_contents($source);
    $filelist = urlencode($html);
//Email after uploading...  
        header( 'Location: http://www.host.com/mailtest.php?name='.$_POST['name'].'&email='.$_POST['email'].'&phone='.$_POST['phone'].'&duedate='.$_POST['duedate'].'&parm1='.$filelist) ;
 
?>
 
 
 
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: URL variable from text file

Post by requinix »

Code: Select all

if($vStatus)
    echo '<status>1</status>';
else
    echo '<status>0</status>';
You can't call header() after outputting something.

And there's still the fact that $_GET["a"] doesn't exist but $_GET["parm1"] does.
tchavez
Forum Newbie
Posts: 6
Joined: Mon Mar 30, 2009 12:57 am

Re: URL variable from text file

Post by tchavez »

The $_GET['a'] was a sub for $_GET['parm1'] parm1 is the real name.

Strange part is this seems to work fine when it type it into the address bar directly.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: URL variable from text file

Post by requinix »

Matter still stands:
tasairis wrote:You can't call header() after outputting something.
tchavez
Forum Newbie
Posts: 6
Joined: Mon Mar 30, 2009 12:57 am

Re: URL variable from text file

Post by tchavez »

Thanks man I fixed it by taking the redirect out of that page and placing it into another page and just setting my app to hit both pages instead of just one.

_____App______
| |
upload.php redirect.php
|
email.php (on different server so Flex wont let me go direct to it)
Post Reply