Jump to content

Recommended Posts

Hello-

 

I'm having trouble figuring out how to transport a variable from one php file to another. Specifically, the name of an image, to be used as a subject in a form mail. I don't even really have the proper vocabulary to describe this, so I'll just try to show my code.

 

Here's the test website in question:

 

http://www.grymttr.com/raj/RajTest/portfolio/

 

When you go to the "portfolio" page, and click on the album (only one at the moment). If you see a picture you are interested in, you click on it, which triggers the file "popup2.php"

 

<?php error_reporting(0); if (isset($_GET['dl'])) {

$file = str_replace('/', DIRECTORY_SEPARATOR, $_GET['src']);

if (strpos($file, '..') !== false) {

exit;

}

$name = basename($file);

$info = pathinfo($name);

$ext = $info['extension'];

$full_path = dirname(__FILE__) . $file;

header("Content-Disposition: attachment; filename=$name");

switch(strtolower($ext)) {

case 'jpg':

$ct = 'image/jpeg';

break;

case 'gif':

$ct = 'image/gif';

break;

case 'png':

$ct = 'image/png';

break;

default:

$ct = 'application/octet-stream';

break;

}

 

header('Content-type: ' . $ct);

header('Content-length: ' . filesize($full_path));

 

$disabled_functions = explode(',', ini_get('disable_functions'));

 

if (is_callable('readfile') && !in_array('readfile', $disabled_functions)) {

readfile($full_path);

} else {

die(file_get_contents($full_path));

}

} else { ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title><?php echo(strip_tags($_GET['title'])); ?></title>

<style type="text/css" media="screen">

/* <![CDATA[ */

* { margin:0; padding:0; overflow:auto;}

/* ]]> */

</style>

 

<script type="text/javascript" charset="utf-8">

function isIE() {

  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);

}

 

function resize(img_w, img_h) {

if (isIE()) {

var h = document.documentElement.clientHeight;

} else {

var h = window.innerHeight;

}

var w = document.body.clientWidth;

var adj_w = img_w - w;

var adj_h = img_h - h;

      window.resizeBy(adj_w, adj_h);

window.focus();

}

</script>

        <link href="mail.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<?php

 

if (strpos($_GET['src'], 'p.php?a=') !== false) {

$src = $_GET['src'];

$bits = explode('?a=', $src);

$src = $bits[0] . '?a=' . urlencode($bits[1]);

} else {

$src = strip_tags($_GET['src']);

}

 

?><div id="container">

        <img class="image" src="<?php echo($src); ?>" alt="<?php echo(strip_tags($_GET['title'])); ?>" />

<div id="form">

 

<form method="POST" action="mailer.php">

Subject: "<?php echo(strip_tags($_GET['title'])); ?>"<br>

<br>

Name:

<input type="text" name="name" size="29"><br>

<br>

E-Mail:

<input type="text" name="email" size="29"><br>

<br>

 

<input type="checkbox" name="check[]" value="print"> print<br>

<input type="checkbox" name="check[]" value="matte"> matte<br>

<input type="checkbox" name="check[]" value="frame"> frame<br>

<br>

Message:<br>

<textarea rows="7" name="message" cols="33"></textarea><br>

<br>

<input type="submit" value="Submit" name="submit">

</form>

</div></div>

   

</body>

</html><?php } ?>

 

and then I have "mailer.php" which actually sends the mail with the variables entered in the form above. The lines highlighted in green grab the "title" of the image, like "GLS002.jpg", which is what I want to be the subject of the e-mail.

 

 

<?php

if(isset($_POST['submit'])) {

 

 

$to = "greg@grymttr.com";

$subject =  $_GET['title'];

$name_field = $_POST['name'];

$email_field = $_POST['email'];

$message = $_POST['message'];

 

foreach($_POST['check'] as $value) {

 

$check_msg .= "Checked: $value\n\n";

 

}

 

$body = "From: $name_field\n\n E-Mail: $email_field\n\n Subject: $subject\n\n Message:\n\n $message\n\n $check_msg";

 

echo "Data has been submitted to $to!";

mail($to, $subject, $body);

 

 

} else {

 

echo "blarg!";

 

}

?>

 

I know the line in red is wrong, but I don't know how to get the title of the image from "popup2.php". If you go to the site and click on an image during the slideshow, you will see the pop-up open, with the title of the window and the "Subject: ....." line filled out correctly, but I can't figure out how to get that variable into the mailer.php file as the subject of the e-mail that gets sent. It's sort of critical, as that's the identification of the image in question. Help!

I should also mention, this is the file "template.php" is what triggers the pop-up in the first place:

<?php

$full = DIR_HOST . '/popup2.php?src=[width:240,height:300,crop:0,quality:90,sharpening:1]&title=[img_src]';

$displayName = __('Image Inquiry', true);
$template = "javascript:if (window.NewWindow) { NewWindow.close(); }; NewWindow=window.open('$full','myWindow','width=700,height=400,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,titlebar=no');NewWindow.focus(); void(0);";
$target = 0;

?>

 

 

So basically in the popup2.php file, I am able to retrieve the desired info ("GLS002.jpg") with

<?php echo(strip_tags($_GET['title'])); ?>

 

but I can't figure out how to call that variable on the mailer.php file.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.