Return to calling web page after PHP action

MY PHP works (PHP support is “automatically” supplied by my hosting company), but when the web page (http://mywebsite/xxx.htm) executes the PHP (uploader.php) from the , the browser displays a new web page (http://mywebsite/uploader.php) and the echo occurs on that page and not on the calling web page (http://mywebsite/xxx.htm). I want the PHP to execute behind the scenes and display any messages on the calling web page or a separate popup window. This is the first time I’ve used PHP, so I’m sure I’m missing something basic here.

My HTML (xxx.htm - snippet below) uses to upload a file:


Choose file to upload:


My PHP (uploader.php - see below) uploads the file:

<?php // Directory where the uploaded file is going to be placed $target_path = "uploads/"; // Use the original filename $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?>

Thanks for any help!

You can make a META, JavaScript or header(‘location’) redirect from PHP if you want to achieve the equivalent of a back-button-action or a redirect, but that won’t help you get the message across. PHP files are parsed (executed) on the server by the PHP engine, and any output is written to the client on the same page. If you want (dynamic) messages on your .htm page, you’ll have to change it into .php and prepare it to receive messages from your upload.php script (or transfer the .htm page, including the functionality, to the upload.php).

Thanks for the great help Zyppora!

Sponsor our Newsletter | Privacy Policy | Terms of Service