Parse error, unexpected T_STRING, expecting T_CASE

Reply

Join Date: Sep 2007
Posts: 3
Reputation: mrsspambo is an unknown quantity at this point 
Solved Threads: 0
mrsspambo mrsspambo is offline Offline
Newbie Poster

Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #1
Sep 13th, 2007
Hello,
I am new to Daniweb and am I glad I found it, there is so much helpful information here for a newbie programer.
This is my error message:
Parse error: parse error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}' in C:\wamp\www\helen\upload.php on line 17
This is my story:
I am building a database for a realestate agent and it needs to be able to upload images to the database. Being green at this I have had a heck of a time finding tutorials that make sense to me regarding uploading files to the database so this is what I have done, please tell me if there is a better way. I am using PHP and I have an 'add.php' page where you would fill in your information and there is a browse button to browse to your image file,
here is the code for the button,
  1. <td><input type="hidden" name="MAX_FILE_SIZE" value="100000" size="32" />
  2. <input name="userfile" type="file" /></td>

I have another page called 'upload.php' that apparently is the page that processes the file information and places it in the database? (I think this is right?)
Here is the code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>uploading</title>
  6. </head>
  7. <body>
  8. <h1>Uploading file</h1>
  9. <?php
  10.  
  11.  
  12. if ($_FILES['userfile']['error'] > 0)
  13. {
  14. echo 'Problem: ';
  15. switch ($_FILES['userfile']['error'])
  16. {
  17. case1: echo 'File exceeded upload_max_filesize'; break; ->THIS IS LINE 17<-
  18. case2: echo 'File exceeded max_filesize'; break;
  19. case3: echo 'File only partially uploaded'; break;
  20. case4: echo 'No file uploaded'; break;
  21. }
  22. exit;
  23. }
  24.  
  25. if ($_FILES['userfile']['type'] != 'image/gif''image/jpg')
  26. {
  27. echo 'Problem:image must be .gif or .jpg';
  28. exit;
  29. }
  30.  
  31. $upfile= '/uploads/'.$_FILES['userfile']['name'];
  32.  
  33. if (is_uploaded_file($_FILES['userfile']['tmp_name']))
  34. if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
  35. {
  36. echo 'Problem: Could not move file to destination directory';
  37. exit;
  38. }
  39. }
  40. else
  41. {
  42. echo 'Problem: Possible file upload attack. Filename: ';
  43. echo $_FILES['userfile']['name'];
  44. exit;
  45. }
  46.  
  47. echo 'File uploaded successfully<br><br>';
  48.  
  49. $fp = fopen($upfile, 'r');
  50. $contents = fread ($fp, filesize ($upfile));
  51. fclose ($fp);
  52.  
  53. $contents = strip_tags($contents);
  54. $fp = fopen($upfile, 'w');
  55. fwrite($fp, $contents);
  56. fclose($fp);
  57.  
  58. echo 'Preview of uploaded images:<br><br>';
  59. echo $contents;
  60. echo '<br><br>';
  61. ?>
  62.  
  63.  
  64.  
  65. </body>
  66. </html>
I have been reading posts from others that have been having similar problems and it seems that it is usually a spelling error or a semicolon is missing but I can't seem to find the error.
And I am wondering if this is even the right way about uploading images.

Incase it is important the information in the data base for the image field is:
Field:thumb1
Type:mediumblob
Attributes:binary
Null:no


Thanks for your help, I feel like this php sql stuff will never make sense.

Cheers!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #2
Sep 13th, 2007
try the case statements like this:

case'1': echo 'File exceeded upload_max_filesize';
break;
case'2': echo 'File exceeded max_filesize';
break;
case'3': echo 'File only partially uploaded';
break;
case'4': echo 'No file uploaded';
break;
I keep hitting "escape", but I'm still here!!!!
:}
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 14
Reputation: kaykays is an unknown quantity at this point 
Solved Threads: 0
kaykays kaykays is offline Offline
Newbie Poster

Re: Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #3
Sep 13th, 2007
There should be a space between case and 1 and add a newline after the semi-colon
as suggested by JeniF

.i.e
case 1:
echo 'File exceeded upload_max_filesize';
break;


Also check the type returned by $_FILES['userfile']['error']
and use 1 or '1' accordingly.
PHP | ASP
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: mrsspambo is an unknown quantity at this point 
Solved Threads: 0
mrsspambo mrsspambo is offline Offline
Newbie Poster

Re: Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #4
Sep 14th, 2007
HI thanks,
but that didn't work, I tried it both ways and now my error is:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\helen\upload.php on line 29

Line 29 is:
  1. if ($_FILES['userfile']['type'] != 'image/gif''image/jpg')

Is this in your opinions the way to upload image files using a browse button?

I appreciate your time so far, please don't leave me yet!!!

Thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 13
Reputation: pzuurveen is an unknown quantity at this point 
Solved Threads: 1
pzuurveen pzuurveen is offline Offline
Newbie Poster

Re: Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #5
Sep 14th, 2007
Your switch problem is fixed.
You just have a bug online 29
trie
  1. if(strpos('*image/gif image/jpg', $Files[' file1']['type'])) {
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: mrsspambo is an unknown quantity at this point 
Solved Threads: 0
mrsspambo mrsspambo is offline Offline
Newbie Poster

Re: Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #6
Sep 14th, 2007
Thanks but it hasn't worked so far,
Here are the new error messages:

  1. Uploading file
  2.  
  3. Warning: move_uploaded_file(/uploads/Lake View.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\helen\upload.php on line 39
  4.  
  5. Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php24A.tmp' to '/uploads/Lake View.jpg' in C:\wamp\www\helen\upload.php on line 39
  6. Problem: Could not move file to destination directory

At least I am getting the uploading file message?

Any further help is still greatly appreciated.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 14
Reputation: kaykays is an unknown quantity at this point 
Solved Threads: 0
kaykays kaykays is offline Offline
Newbie Poster

Re: Parse error, unexpected T_STRING, expecting T_CASE

 
0
  #7
Sep 14th, 2007
Check the directory permissions in the folder uploads where the file is to be uploaded?
PHP | ASP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC