PDA

View Full Version : variables global/local again?



bluewalrus
10-28-2009, 10:33 PM
How can I change the value of "type" it seems to be locked in to the global value. I get this error in fire bug "setting a property that has only a getter" for the code the entered below but if i change the onchange = "type..." to onechange = "var type ..." the alerts work. I'm not trying to get the alerts to work though so i'm not even sure if this is the right track I want the uploader address to get the value from the option value. Thanks for ny ideas.

This is using jquery.


<script type="text/javascript">
var type ="global";
$(function(){
$('#swfupload-control').swfupload({
upload_url: "upload-file.php?id=" + <?php echo $id_is; //send upload-file correct id?> + "&type=" + type,
file_post_name: 'uploadfile',
file_size_limit : "0",
file_types : "*.*",
file_types_description : "All file types are allowed.",
file_upload_limit : 0,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
button_width : 114,
button_height : 29,
button_placeholder : $('#button')[0],
debug: false
})
.bind('fileQueued', function(event, file){
var listitem='<li id="'+file.id+'" >'+
'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
'<div class="progressbar" ><div class="progress" ></div></div>'+
'<p class="status" >Pending</p>'+
'<span class="cancel" >&nbsp;</span>'+
'</li>';
$('#log').append(listitem);
$('li#'+file.id+' .cancel').bind('click', function(){
var swfu = $.swfupload.getInstance('#swfupload-control');
swfu.cancelUpload(file.id);
$('li#'+file.id).slideUp('fast');
});
// start the upload since it's queued
$(this).swfupload('startUpload');
})
.bind('fileQueueError', function(event, file, errorCode, message){
alert('Size of the file '+file.name+' is greater than limit');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued);
})
.bind('uploadStart', function(event, file){
$('#log li#'+file.id).find('p.status').text('Uploading...');
$('#log li#'+file.id).find('span.progressvalue').text('0%');
$('#log li#'+file.id).find('span.cancel').hide();
})
.bind('uploadProgress', function(event, file, bytesLoaded){
//Show Progress
var percentage=Math.round((bytesLoaded/file.size)*100);
$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
$('#log li#'+file.id).find('span.progressvalue').text(percentage+'%');
})
.bind('uploadSuccess', function(event, file, serverData){
var item=$('#log li#'+file.id);
item.find('div.progress').css('width', '100%');
item.find('span.progressvalue').text('100%');
var pathtofile='<a href="./../../files/ftp_upload/<?php echo $id_is; //link to uploaded file?>/'+file.name+'" target="_blank" >view &raquo;</a>';
item.addClass('success').find('p.status').html('Done!!! | '+pathtofile);
})
.bind('uploadComplete', function(event, file){
// upload has completed, try the next one in the queue
$(this).swfupload('startUpload');
})

});
</script>
</head>
<body>
<form name="example">
<select name="upload_type" onchange="type = document.example.upload_type.options[document.example.upload_type.selectedIndex].value; alert(type);">
<option value="1">text</option>
<option value="2">Video</option>
<option value="3">comments</option>
<option value="4">Other</option>
</select>
</form>

jscheuer1
10-28-2009, 11:47 PM
There could be other problems but the word type is reserved to a degree, try a different name. In the meantime I'll have a closer look at the code.

jscheuer1
10-28-2009, 11:57 PM
OK, your comment looks suspicious:


upload_url: "upload-file.php?id=" + <?php echo $id_is; //send upload-file correct id?> + "&type=" + type,

I'd try:


upload_url: "upload-file.php?id=" + <?php echo $id_is; /* send upload-file correct id */ ?> + "&type=" + type,

Or just getting rid of the comment altogether. And you have another similar instance that should be fixed later in the code.

If you want more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

bluewalrus
10-29-2009, 05:27 AM
The // is a single line comment in php and that echos fine on the actually page (the comment doesn't show) so I think that part should be fine.

Here's a link to where it is not working http://christophermacdonald.net/JQTEST/cookiefunctions/multifileduload/index.php?id=1246

Thanks for any help you can offer.

I also changed the name from type to typer with no luck. The result on the next page still had the type as "global", I get an email that tells me what the value of it is.

jscheuer1
10-29-2009, 06:44 AM
Well changing the select clearly changes the value of the variable typer on the page. What happens on other pages isn't clear to me. I have nothing to upload, nor am I clear as to what would be expected if I did, so I'm not sure how I would check that.

However, once you change pages, the value of the typer variable (like any javascript variable) is lost to javascript. It can only be preserved via PHP post, session, or as part of a query string (get) parsed by PHP or javascript on the next page.

Now, it is fair to assume (though I may be missing something) that:


$(function(){
$('#swfupload-control').swfupload({
upload_url: "upload-file.php?id=" + 1246 + "&type=" + typer,
file_ . . .

is executed at the time of jQuery's document.ready. The property upload_url is set at that time, when typer equals 'global'. If you want to change the portion of the upload_url property first represented by typer after that, you must access the upload_url property, not merely the typer variable. I see no other reference to the upload_url property in the code, so I assume it remains as whatever it was set to at document.ready.

bluewalrus
10-29-2009, 01:42 PM
Oh okay, the form is inside the flash movie I think so i can't get the post or get data from that. Is there a way I could trigger the on click of the submit button to run through that instead of setting it when the page finishes loading, how is it being called for when the page finishes loading also or where? I thought that was done at <body onload="something();">.

jscheuer1
10-29-2009, 03:27 PM
This would appear to be more of a Flash coding issue then. There is no onload event in the body tag. The form in the page's HTML source code never submits, at least not in the normal fashion, it has no submit button, nor any other way of being submitted unless the Flash were to submit it via javascript, or if one of your scripts were to. However, I tried a test upload, and it appeared to get the file type correctly - not from the little select, but probably from the server side.

What do you want to have happen? I'm imagining that upon completion of the upload, you want the page to refresh so that the uploaded files display will update. That could be called from the Flash as a javascript:


window.loaction.reload();

possibly even just updated via AJAX, or there may even be code in Flash that could do one or the other of these things directly. In any case, something in the Flash code must register the completion of the upload, either by its being told by the server that the file is done, or through something internal in the Flash applet. So whatever sends that signal could be grabbed to do a page reload or whatever.

I'm not sure why you need the Flash though, unless it is for the progress bar display. It might not even have a form in it, simply a file input element would be all that would be required. Where'd you get all this stuff? There may be documentation.

bluewalrus
10-29-2009, 03:38 PM
I don't have acess to the fla I only have the swf so I can't make any changes there. I tried to make the form submit when the submit button is clicked but it's not working it says "uncaught exception: Could not find the placeholder element: ".

I've figured out I can't get the value through the address bar so I'm moving on to trying to get the value through php with a post but I need to use javascript to submit the select value as a post to the next page before the jquery sends it.

jscheuer1
10-29-2009, 04:01 PM
There is no submit button. And, as far as I can tell, there is no "next page".

Forget for a moment how. What exactly do you want to have happen? What will the end result be?

Also, I repeat, where did you get these scripts and the Flash? There may be documentation.

bluewalrus
10-29-2009, 04:41 PM
Sorry missed the part about where I got the code from. I got the code from here http://demo.webdeveloperplus.com/jquery-swfupload/ . I want to be able to upload multiple files to the server in a specific directory based on the id if that id does not have it's own directory it creates the directory. An email is then sent to people based on what type of file was uploaded. I have all this done except for the type of file, this can't be done by the file format because file changes can be made to the same file format. This index.php uploads to upload-file.php both contain ?id= after there names and that tells where to send the file.