Javascript problem

Hi Clifton,
This is not directly related to Powerpac but I'm completely baffled by this problem and I'd be most grateful if you could spare the time to give me your thoughts on this.
I am using an open source uploader to upload video files to the server. It has taken me a very long time to get it to do what I want it to do. It's almost perfect now but there's one BIG problem:
If I always upload files to the same directory on the server everything works. But I figure that if my app has multiple users it would be a mistake to use the same directory for all users so each user must have a separate directory for uploaded files. My system is as follows:
- I create a directory with the required name in the user's directories to receive the file to be uploaded.
- I upload the file to the user's directory for uploaded files (which contains the appropriate php file - this is a very complicated file but I have tested it and I know it works anywhere on the server).
- I then use another php file on the server to move the uploaded file from the user's directory for uploaded files to the newly created directory. (The user's directory for uploaded files is then empty again.)
All this works! So what is the problem?
The problem is is the javascript code I in an embedded html I load with pgGotoURL()
Here is the (Jquery) part that does the uploading:
theURL is a global variable. If I define this variable in advance in the script section of the html like this: var theURL = "Mimine's_Academy/teachers/BLOGGS_Bill/perso/"; there is no problem. The jquery function accepts the variable
theURL and the task is completed seamlessly. However this is not what I want. I want to define theURL dynamically like this:
It doesn't work. I don't understand why because when I include this:
The alert displays the same (!!!) So why doesn't the variable theURL function in this case? Could it be some kind of security restriction that rejects the variable if it's just been redefined?
I'm hoping you might have some clue. I haven't! The only other way I could make it work would be to copy the whole uploading html into every user's folder but it seems a bit excessive.
This is not directly related to Powerpac but I'm completely baffled by this problem and I'd be most grateful if you could spare the time to give me your thoughts on this.
I am using an open source uploader to upload video files to the server. It has taken me a very long time to get it to do what I want it to do. It's almost perfect now but there's one BIG problem:
If I always upload files to the same directory on the server everything works. But I figure that if my app has multiple users it would be a mistake to use the same directory for all users so each user must have a separate directory for uploaded files. My system is as follows:
- I create a directory with the required name in the user's directories to receive the file to be uploaded.
- I upload the file to the user's directory for uploaded files (which contains the appropriate php file - this is a very complicated file but I have tested it and I know it works anywhere on the server).
- I then use another php file on the server to move the uploaded file from the user's directory for uploaded files to the newly created directory. (The user's directory for uploaded files is then empty again.)
All this works! So what is the problem?
The problem is is the javascript code I in an embedded html I load with pgGotoURL()
Here is the (Jquery) part that does the uploading:
- Code: Select all
// This does the uploading.
$(document).ready(function() {
'use strict';
$('#fileupload').fileupload({
url: theURL,
maxFileSize: sizeLimit,
acceptFileTypes: /(\.|\/)(mp3|ogg|mp4|mov|flv|gif|jpe?g|png)$/i,
add : function(e,data){
$("#test").on("click",function(){
if (preventUpload == false) {
data.submit();
} else {
alert ("This type of file cannot be uploaded.")
}
})
},
done: function(e, data) {
moveFile();
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css('width', progress + '%'
);
}
});
});
theURL is a global variable. If I define this variable in advance in the script section of the html like this: var theURL = "Mimine's_Academy/teachers/BLOGGS_Bill/perso/"; there is no problem. The jquery function accepts the variable
theURL and the task is completed seamlessly. However this is not what I want. I want to define theURL dynamically like this:
- Code: Select all
function uploadFile(uploadFolder) {
theURL = uploadFolder;
obj = document.getElementById("startUpload");
obj.click();
}
It doesn't work. I don't understand why because when I include this:
- Code: Select all
function uploadFile(uploadFolder) {
if(uploadFolder === theURL) {
alert("the same");
} else {
alert("not the same");
}
theURL = uploadFolder;
obj = document.getElementById("startUpload");
obj.click();
}
The alert displays the same (!!!) So why doesn't the variable theURL function in this case? Could it be some kind of security restriction that rejects the variable if it's just been redefined?
I'm hoping you might have some clue. I haven't! The only other way I could make it work would be to copy the whole uploading html into every user's folder but it seems a bit excessive.