Parse Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Parse Error

Post by michaelk46 »

I am getting a parse error and not sure how to fix it...
Here is the code...

Code: Select all

 
if ($_SERVER['REQUEST_METHOD'] != "POST")
    {                                                                  
        include "upload.html.php";
    }
else    
    {
        switch($_FILES['upload']['error']):
            case UPLOAD_ERR_OK:
                $ext = strtolower(pathinfo($_FILES['name']['name'], PATHINFO_EXTENSION));
                switch ($ext):
                    case 'csv':
                        $destfile = '\Files\csv\ ' . basename($_FILES['name']['upload'];
                        $ret = @move_uploaded_file($_FILES['name']['tmp_name'], $destfile);
                        if ($ret === false)
                            echo htmlspecialchars('Unable to move file', ENT_QUOTES, 'utf-8')
                        else
                            echo htmlspecialchars('File moved successfully', ENT_QUOTES, 'utf-8')
                    break;
                    case 'jpg': case'jpeg':
                        $destfile = '../www/Test/Upload/Files/images/' . basename($_FILES['name']['upload'];
                        $ret = @move_uploaded_file($_FILES['name']['tmp_name'], $destfile);
                        if ($ret === false)
                            echo htmlspecialchars('Unable to move file', ENT_QUOTES, 'utf-8')
                        else
                            echo htmlspecialchars('File moved successfully', ENT_QUOTES, 'utf-8')
                    break;
                    default:
                        echo htmlspecialchars('Invalid File Type', ENT_QUOTES, 'utf-8');
                    break;
            break;
            case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE:
                $output = "Incorrect File Size, Please Reupload"
                include 'output.html.php';
            break;
            case UPLOAD_ERR_PARTIAL:
                $output = 'Partial file found, Please reupload';
                include 'output.html.php';
            break;
            case UPLOAD_ERR_NO_FILE: 
                $output = 'No file found, Please reupload';
                include 'output.html.php';
            break;
            case UPLOAD_ERR_NO_TMP_DIR:
                $output = 'Incorrect Directory';
                include 'output.html.php';
            break;
            default:
            break;      
 
On line 13...
notice that there is a space between the backslash after csv and the quotation mark and everything with the variable looks okay...

But without that space, the variable name becomes a part of the string and does not populate the script with the appropriate value... Plus I am getting a parse error on that line. More than likely the two problems are related, but I am not sure....

Why???
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Re: Parse Error

Post by jason »

You are missing a closing ')' for basename.

Also, the backslash is an escape character. Use \\ and remove the space before the single quote. \\ basically means that the first backslash escapes the second backslash, allowing it to be used as a single, normal backslash. Do the same thing for the first \ as well.
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: Parse Error

Post by michaelk46 »

Oh.. Thank You.... I have been running over that for about two hours now... It's funny how the simplest errors escape you...
Post Reply