Page 1 of 1

Parse Error

Posted: Mon Jan 04, 2010 7:02 am
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???

Re: Parse Error

Posted: Mon Jan 04, 2010 7:30 am
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.

Re: Parse Error

Posted: Mon Jan 04, 2010 7:54 am
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...