Solved

pass variable to swfupload

Posted on 2010-09-20
10
739 Views
Last Modified: 2012-06-22
How could I pass the value of "$house_id" to update.php in the following code:
<!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" >
<head>
<title>SWFUpload Demos - Simple Demo</title>
<link href="default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="swfupload.js"></script>
<script type="text/javascript" src="js/swfupload.queue.js"></script>
<script type="text/javascript" src="js/fileprogress.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script type="text/javascript">
		var swfu;

		window.onload = function() {
			var settings = {
				flash_url : "Flash/swfupload.swf",
				upload_url: "upload.php",
				post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},
				file_size_limit : "100 MB",
				file_types : "*.*",
				file_types_description : "All Files",
				file_upload_limit : 100,
				file_queue_limit : 0,
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,

				// Button settings
				button_image_url: "images/TestImageNoText_65x29.png",
				button_width: "65",
				button_height: "29",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '<span class="theFont">Hello</span>',
				button_text_style: ".theFont { font-size: 16; }",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
				queue_complete_handler : queueComplete	// Queue plugin event
			};

			swfu = new SWFUpload(settings);
	     };
	</script>
</head>
<body>
<div id="header">
	<h1 id="logo"><a href="../">SWFUpload</a></h1>
	<div id="version">v2.2.0</div>
</div>

<div id="content">
	<h2>Simple Demo</h2>
	<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
		<p>This page demonstrates a simple usage of SWFUpload.  It uses the Queue Plugin to simplify uploading or cancelling all queued files.</p>

			<div class="fieldset flash" id="fsUploadProgress">
			<span class="legend">Upload Queue</span>
			</div>
		<div id="divStatus">0 Files Uploaded</div>
			<div>
				<span id="spanButtonPlaceHolder"></span>
				<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
			</div>

	</form>
</div>
</body>
</html>

Open in new window

0
Comment
Question by:hrolsons
  • 5
  • 5
10 Comments
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 33718344
The form is submitted via POST to your update script, so to pass in any extra variables, simple include them inside your form, either as text fields, but more likely as hidden inputs.



<div id="content">

	<h2>Simple Demo</h2>

	<form id="form1" action="index.php" method="post" enctype="multipart/form-data">

		<p>This page demonstrates a simple usage of SWFUpload.  It uses the Queue Plugin to simplify uploading or cancelling all queued files.</p>



<input type="hidden" name="house_id" value="<?php echo $house_id; ?>" />





			<div class="fieldset flash" id="fsUploadProgress">

			<span class="legend">Upload Queue</span>

			</div>

		<div id="divStatus">0 Files Uploaded</div>

			<div>

				<span id="spanButtonPlaceHolder"></span>

				<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />

			</div>



	</form>

</div>

Open in new window

0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 33718355
Oops, forgot the next bit.

In your update.php file, the value will be available in the $_POST array.



$house_id = $_POST['house_id'];

Open in new window

0
 

Author Comment

by:hrolsons
ID: 33718620
hmmmm, I'm doing something wrong, as I can see the value of "house_id" does exist on the form:

<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p>This page demonstrates a simple usage of SWFUpload.  It uses the Queue Plugin to simplify uploading or cancelling all queued files.</p>
<input type="hidden" name="house_id" value="123" />

And I did put:
$house_id = $_POST['house_id'];
in my update.php file

But, when update.php stores the data, house_id still stores as "0".

Normally I would throw some echo statements into update.php and find the value of "house_id" at various points, but in this case it doesn't work because my swfupload original page does not output the results of update.php.

0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 33718812
Ok,

I've just had another look through your code. In the example above your form action is set to index.php, but you seem to be overriding this with the Javascript and setting it to update.php. Within the Javascript that overrides the default form action you have a line that sets the post_params. You should try setting the house_id inside there instead.

In the code you posted with the question, have a look at line 17, It's setting additional info to be be passed through post, so you should add it to that.

Also, a neat little trick for debugging when no output is generated is to write to a log file. You can put this line in your update.php file and check the contents of the debug.log file (in the same folder as the script) after you've run the script.

file_put_contents("debug.log", "Whatever you want to write to the log file.\n", FILE_APPEND);






post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "house_id" : <?php echo $house_id; ?>"},

Open in new window

0
 

Author Comment

by:hrolsons
ID: 33719324
I see what you're saying.  And now after putting a double-quote in before "<?php" in your code, and then changing _POST to _GET in update.php, things are working as expected.  Thank you very much!!!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:hrolsons
ID: 33719412
Dang it!!!  I must have changed something because now it's not working.
0
 

Author Comment

by:hrolsons
ID: 33719458
I used your debug tip:

      foreach ($_GET as $key => $value)
      {
            file_put_contents("debug.log", "$key - $value\n", FILE_APPEND);
      }

And I get:

Warning: file_put_contents(debug.log) [function.file-put-contents]: failed to open stream: Permission denied in /usr/local/www/vhosts/mysite.com/html/CRM/upload/upload.php  on line 16

I know this is a permission issue and doesn't belong in this dialog.
0
 

Author Comment

by:hrolsons
ID: 33719584
I think all is solved now.  All that needed to be changed was the one double-quote in your message  ID: 33718812
0
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 33719746
Sorry,

Just had another look at the code I posted, and yeah, there was a double quote missing. Doh!!

Corrected code below but I guess you've figured it out :)


post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "house_id" : "<?php echo $house_id; ?>"},

Open in new window

0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 33719751
By the way, you (the script) need write permission on the folder you're trying to write the debug to.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now