Jump to content

PHP Upload Script


wowcrofty

Recommended Posts

I currently have the following script used on my site to upload files.  When the linked web page executes it, however, I receive the infamous Parse Error - Unexpected '<' in x:/xxxx.  The problem lies in Line 11 where I attempt to define a command that will display a message box to the user upon successful file upload.  The syntax is not correct and I was hoping someone would be able to help me with it.  Here is the contents of the PHP file.

 

<?php
// Where the file is going to be placed
$target_path = $_SERVER['DOCUMENT_ROOT'] . "/file_uploads/";

/*Add the original filename to our target path.
Result is "uploads/filename.extension"*/
$target_path=$target_path.basename($_FILES['file']['name']);

//Move file to upload directory
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo <script type="text/javascript">alert("Upload was successful.  Thank you for your contribution")</script>;
} else{
echo "There was a problem submitting the file.  Plese try again!";
}
?>

 

Thank you in advance for any help.

 

Link to comment
https://forums.phpfreaks.com/topic/213153-php-upload-script/
Share on other sites

This has helped me but I have a question on how to re-direct from here.

 

under my alert(), I have a header(Location).  If I comment out the header(), the alert runs fine, otherwise it just runs the redirect.

 

Is there a way that the alert will run and then when you press the OK button in the dialog box, the rest of the code below will run?

 

Thanks as always.

Link to comment
https://forums.phpfreaks.com/topic/213153-php-upload-script/#findComment-1110198
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.