What is wrong.....

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
phelpsa
Forum Commoner
Posts: 48
Joined: Thu Feb 17, 2005 1:05 pm

What is wrong.....

Post by phelpsa »

....with this code??

It says there is a parse error in line 52???

Code: Select all

<html>
<head>
    <title>Uploading.....</title>
</head>
<body>
<h1>Uploading Picture</h1>
<?php

    if ($_FILES['userfile']['error'] > 0)
    {
       echo 'Problem:  ';
       switch ($_FILES['userfile']['error'])
       {
        case 1:   echo 'File exceeded upload_max_filesize'; break;
        case 2:   echo 'File exceeded max_file_size'; break;
        case 3:   echo 'File only partially uploaded'; break;
        case 4:   echo 'No file uploaded'; break;
       }
       exit;
    }

//put the file where we'd like it
$upfile = '/uploads/'.$_FILES['userfile']['name'] ;

if (is_uploaded_file($_FILES['userfile']['tmpname']))
{
   if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
    {
       echo 'Problem: Could not move file to directory';
       exit;
    }
}
else
{
   echo 'Problem: Possible file upload attack. Filename: ';
   echo $_FILES['userfile']['name'];
   exit;

echo 'File uploaded successfully<br><br>';

//reformat the file contents
$fp = fopen($upfile, 'r');
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);

//show what was uploaded
echo 'Preview of upload';
echo $contents;
echo '<br><hr>';
?>
</body>
</html>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Code: Select all

else
{
   echo 'Problem: Possible file upload attack. Filename: ';
   echo $_FILES['userfile']['name'];
   exit;
You do not close this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

phelpsa, please work on coming up with decent topic titles... thanks.
Post Reply