?
Solved

pass a variable to my php page.

Posted on 2008-06-15
7
Medium Priority
?
201 Views
Last Modified: 2012-06-27
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
Comment
Question by:johnwry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:afzz
ID: 21788109
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
 

Author Comment

by:johnwry
ID: 21788115
didn't work. I had tried that as well.
0
 

Author Comment

by:johnwry
ID: 21788473
ok. upload.php:
name is echo'd but not bookid.
<?php
 
echo $_GET['name'];
echo $_GET['bookid'];
 
?>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:afzz
ID: 21788546
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
 
LVL 29

Expert Comment

by:fibo
ID: 21789220
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
 
LVL 2

Expert Comment

by:pain_is_relative
ID: 21791251
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
 

Accepted Solution

by:
johnwry earned 0 total points
ID: 21791951
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question