• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

pass a variable to my php page.

hello,
i totally don't understand the logic behind javascript. It's been the most frustrating thing to try to to discipher.
I have this bit of code and I need to pass a variable ($bookid)  to the upload.php page. Sorry for the lengthy bit of code.
<?php
 
//session_start();
 
 
 
require_once("getid3/getid3.php"); 
 
$id3 = new getID3();
 
 
 
?>
 
<!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">
 
<head>
 
<title>Flash File Uploader</title>
 
<script type="text/javascript" src="http://www.era404.com/js/swfobject.js"></script>
 
<link href="_css/era404.css" rel="stylesheet" type="text/css" />
 
<script src="_js/swfobject.js" type="text/javascript"></script>
 
 
 
	<base target="_self" />
 
	<script type="text/javascript">
 
	function formValidator()
 
	{
 
		var up = document.getElementById("flash_uploader");
 
		var bkid = document.getElementById("bookid");
 
		var fb = document.getElementById('flash_block');
 
		var upload_button = document.theForm.action_upload;
 
		var upload_url = "upload.php";
 
		up.SetVariable("upload_to", upload_url);
 
		up.SetVariable("ul", "100");
 
		upload_button.disabled='true';
 
		return false;
 
	}
 
	function upload_complete(name,size,type,ft)
 
	{
 
		window.location="index.php?name="+name+"&size="+size+"&type="+type+"&exts="+ft;
 
	}
 
	function fileProps(name,size,type,cdate,mdate)
 
	{
 
		var props = document.getElementById('props');
 
		props.innerHTML = "<div class='sucErr'><div class='tableHeader' style='width: 400px; height: 20px; padding-top: 5px;'>Selected File:</div><br /><table border='0' cellspacing='0' cellpadding='0' style='margin:10px;'><tr><td width='100'><b>NAME:</b></td><td> "+name+"</td></tr><tr><td><b>SIZE:</b></td><td> "+size+"</td></tr><tr><td><b>TYPE:</b></td><td> "+type+"</td></tr><tr><td><b>CREATED:</b></td><td> "+cdate+"</td></tr><tr><td><b>MODIFIED:</b></td><td> "+mdate+"</td></tr></table></div>";
 
		props.style.display = "block";
 
	}
 
	function thumbs()
 
	{
 
		var thumbs = document.getElementById('thm');
 
		if(thumbs.checked == true) { window.location = "index.php?thm=1"; }
 
		else { window.location = "index.php"; }
 
	}
 
</script>
 
</head>
 
<a name="top"></a>
 
<body>
 
<?php
 
 
 
if(@!empty($_GET['name']) && file_exists(getcwd().'/book_images/'.$_GET['name'])){
 
 
 
 
 
}
 
?>
 
 
 
 
 
<body>
 
<center>
 
 
 
		<p>
 
<div id='props' style='display:none;font: 8pt Verdana, Georgia, Sans-serif !important;width:360px;margin:10px;padding:10px;'></div>
 
<form method="post" enctype="multipart/form-data" name="theForm" id="theForm" onSubmit="return formValidator();">
 
<?php
 
 
 
 
 
if(@!empty($_GET['name'])){
 
	echo "<div id='props' style='display:block;font: 8pt Verdana, Georgia, Sans-serif !important;width:360px;margin:10px;padding:10px;'>";
 
	if(file_exists(getcwd().'/book_images/'.$_GET['name'])){	
 
	echo "<div class='sucErr'><div class='tableHeader' style='width: 400px; height: 20px; padding-top: 5px;'>Exito:</div><br />";
 
		echo "<span class='standardCopy'><i>{$_GET['name']}</i><br /> Se ha subido con exito.".$sz."</span><br />";
 
	}else{
 
		echo "<div class='sucErr'><div class='tableHeader' style='width: 400px; height: 20px; padding-top: 5px;'>Error:</div><br />";
 
		$_GET['exts']   = explode(",",$_GET['exts']);
 
		$_GET['allowed'] = (in_array(LTRIM(strtolower($_GET['type']),"."),$_GET['exts']) ? "yes" : "no");
 
		$maxsize = return_bytes(ini_get('post_max_size'));
 
		echo "<span class='standardCopy'>No se pudo subir.</span><br />";
 
		if($_GET['allowed'] == "no")
 
		{
 
			echo "<span class='standardCopy'><b>Filetype (".$_GET['type'].") no permitido.</b></span><br /><br />";
 
		}
 
		else
 
		{
 
			echo ($_GET['size'] > $maxsize ? "<span class='standardCopy'><b>Archivo ({$_GET['size']}) es muy grande ($maxsize).</b></span><br /><br />" : "<br /><br />");
 
		}
 
 
 
		echo "<span class='boldCopy'>ARCHIVO: </span><span class='standardCopy'>".$_GET['name']. "</span><br />";
 
		echo "<span class='boldCopy'>TIPO: </span><span class='standardCopy'>".$_GET['type']. "</span><br />";
 
		echo "<span class='boldCopy'>TAMAO: </span><span class='standardCopy'>".$_GET['size']. "</span><br />";
 
		echo "<span class='boldCopy'>PERMITIDO: </span><span class='standardCopy'>".$_GET['allowed']. "</span><br />";
 
	}
 
	echo "</div></div>";
 
	$_GET = array();
 
 
 
}
 
 
 
 
 
 
 
//useful functions
 
function return_bytes($val) {
 
    $val = trim($val);
 
    $last = strtolower($val{strlen($val)-1});
 
    switch($last) {
 
        // The 'G' modifier is available since PHP 5.1.0
 
        case 'g':
 
            $val *= 1024;
 
        case 'm':
 
            $val *= 1024;
 
        case 'k':
 
            $val *= 1024;
 
    }
 
    return $val;
 
}
 
session_destroy();
 
?>
 
<div id="bookid"><?php echo $bookid;?></div>
 
<div id="flash_block" style="display: visible;">
 
						<div id="flashcontent"></div>
 
					</div>
 
					<script type="text/javascript">
 
						var fo = new SWFObject("uploader.swf?ul=100", "flash_uploader", "435", "40", 8, "#FFFFFF", true);
 
						fo.addParam("allowScriptAccess", "sameDomain");
 
						fo.addParam("quality", "high");
 
						fo.addParam("scale", "noscale");
 
						fo.addVariable("to", "upload.php");
 
						fo.addVariable("limit", "100");
 
						fo.addVariable("types", "video|text|pdf|image|audio");
 
						fo.write("flashcontent");
 
					</script>
 
 
 
		<!--<input name="action_upload" type="submit" value="Upload Video"><br>-->
 
</form>
 
 
 
 
 
 
 
</center>
 
</body>
 
</html>

Open in new window

0
johnwry
Asked:
johnwry
1 Solution
 
afzzCommented:
change the following at the bottom of the code and in upload.php

$bookid=$_REQUEST['bookid'];
<div id="bookid"><?php echo $bookid;?></div>
 
<div id="flash_block" style="display: visible;">
 
						<div id="flashcontent"></div>
 
					</div>
 
					<script type="text/javascript">
 
						var fo = new SWFObject("uploader.swf?ul=100", "flash_uploader", "435", "40", 8, "#FFFFFF", true);
 
						fo.addParam("allowScriptAccess", "sameDomain");
 
						fo.addParam("quality", "high");
 
						fo.addParam("scale", "noscale");
 
						fo.addVariable("to", "upload.php?bookid=<?=$bookid?>");
 
						fo.addVariable("limit", "100");
 
						fo.addVariable("types", "video|text|pdf|image|audio");
 
						fo.write("flashcontent");
 
					</script>
 
 
 
		<!--<input name="action_upload" type="submit" value="Upload Video"><br>-->
 
</form>
 
 
 
 
 
 
 
</center>
 
</body>
 
</html>

Open in new window

0
 
johnwryAuthor Commented:
didn't work. I had tried that as well.
0
 
johnwryAuthor Commented:
ok. upload.php:
name is echo'd but not bookid.
<?php
 
echo $_GET['name'];
echo $_GET['bookid'];
 
?>

Open in new window

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
afzzCommented:
in your code, the only place you are passing the name variable is in the following function and it is going to index.php. you have to do a similar thing to pass the bookid to whereever you are passing the name variable.

you can call the function upload_complete with the extra var as shown below and it will get passed to the php page. same with wherever you pass vars to upload.php
	function upload_complete(name,size,type,ft,bkid)
 
	{
 
		window.location="index.php?name="+name+"&size="+size+"&type="+type+"&exts="+ft+"&bookid="+bkid;
 
	}

Open in new window

0
 
Bernard S.CTOCommented:
I would probably activate / uncomment session_start to be sur that $_GET and $_POST do work as expected

<?php
 session_start();
 require_once("getid3/getid3.php");
0
 
pain_is_relativeCommented:
What you need to do is attach your variable to the upload URL...

so: your upload url would need to be:

"upload.php?bookid=313"

(asuming that bookid is 313)
Then it would be in the GET data. and avaiable to your upload.php script.

obviuosly your javascript is making a request to your php script, much like you would if you were using a browser. the easiest way to pass on a variable whilst doing that is by attaching them after the url.. (this is a GET method) the other moethod is by POST, where you attach the information to the HTTP headers, which is a farmore complex task than is needed here.


0
 
johnwryAuthor Commented:
ok. i've got it working. I changed this bit of code:
function upload_complete(name,size,type,ft,bkid)
 
 
 
	{
 
 
 
		window.location="index.php?name="+name+"&size="+size+"&type="+type+"&exts="+ft+"&bookid=<?php echo $bookid ?>";
 
 
 
	}

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now