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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.