?
Solved

pass variable to swfupload

Posted on 2010-09-20
10
Medium Priority
?
744 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
[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
  • 5
  • 5
10 Comments
 
LVL 43

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 43

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 43

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
 

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 43

Accepted Solution

by:
Chris Stanyon earned 2000 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 43

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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