Solved

pass a variable to my php page.

Posted on 2008-06-15
7
189 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

864 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now