I am currently designing an HTML5 Canvas application and am using an Image Uploader so that users can upload local images to the server and then modify the image on canvas (as a number of manipulations to external sources will give you a security exception).
I have some JS included that goes something like this:
<script type="text/javscript">
var editImage = new Image; // Global scope; not in a function
function setupCanvas() {}
</script>
Once the image has been successfully loaded I echo something like this:
echo '
<script type="text/javascript">
alert("'.$upload_image.'");
window.editImage=new Image();
window.editImage.src=\''.$upload_image.'\';
alert(window.editImage.src);
setupCanvas();
</script>'
Now the output I get from the alert() statements are $upload_image. But when I check FireBug, it'll say that the editImage var that I have declared GLOBALLY in a separate script is still the ORIGINAL image source, NOT $upload_image. Furthermore, it'll say the setupCanvas() method that I have called will be UNDEFINED, although it is in the GLOBAL scope.
I am assuming when I do this with PHP there must be some scope issues - is there a way around this?
echo
on the page? – tjm Dec 18 '10 at 5:28