After one of my PHP Scripts, I am running this code
echo ('<script type="text/javascript">alert("hi");</script>');
However, no alert is shown. Is this a limitation with how the DOM is loaded, and if so, how do I work around it?
After one of my PHP Scripts, I am running this code
echo ('<script type="text/javascript">alert("hi");</script>');
However, no alert is shown. Is this a limitation with how the DOM is loaded, and if so, how do I work around it?
Try to use javascript in this way:
window.top.window.yourFunctionName();
in your case, it would be like:
echo ('<script type="text/javascript">window.top.window.alert("hi");</script>');
The issue here is that you have a typo. It should be $_FILES
not $FILES
Also you are not using the move_uploaded_file()
function properly. The syntax is as follows
move_uploaded_file($tmp_name, "$uploads_dir/$name");
Where
$tmp_name = $_FILES["file"]["tmp_name"];
$uploads_dir = 'Location Folder of where the file should be stored';
$name = $_FILES["file"]["name"];
Also i strongly advise you add some validations for this upload module. As it is, malicious files such as trojans etc can easily be uploaded.
As @mike suggested, the problem is that simply appending a script to the DOM usually doesn't execute it. The solution is to change the logic of the code.
Either the PHP code should redirect the browser to another page, or the JavaScript AJAX should have an event listener for the upload completion.