Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i get this error when using my php code

PHP Syntax Check: Parse error: syntax error, unexpected '}' in your code on line 7

please help me i dont understand what ive done wrong here php code :

<?php


if ( $ready == "false" ) { 
$rand =  chr(rand(97, 122)). chr(rand(97, 122)). chr(rand(97, 122)); 
$folder = "uploads/".$rand 
}

if ( !is_dir($folder) ) {
    $ready = "true"
}
if ( is_dir($folder) ) {
    $ready = "false"
}

if ( $ready == "true" ) {
$that = "yes"
mkdir("uploads/".$rand);
$to = "Uploads/".$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], $to);
echo "uploaded";
}
?>


<form method="post" enctype="multipart/form-data">
<label>Choose a file:</label>
<input type="hidden" name="upload" value="1">
<input type="file" name="file">
<input type="submit" value="upload" onclick="$other = "yes""/>

</form>
share|improve this question

closed as off-topic by nickb, John Conde, Amal Murali, halfer, Andy G Jul 27 '13 at 14:42

  • This question does not appear to be about programming within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

5  
This question appears to be off-topic because it is about a syntax error and is unlikely to help future visitors. –  nickb Jul 27 '13 at 14:37
    
If you have a question like this, look at line 7, or the proceeding line, to see what is wrong with the code. If you install an IDE (like Netbeans or Eclipse) it will show you what is wrong with it, without you having to run the code. –  halfer Jul 27 '13 at 14:38
    
Please take a look at your code. It misses ; in several places. –  Amal Murali Jul 27 '13 at 14:39
    
damn man, you missed so many ; I thought this was VB –  meda Jul 27 '13 at 14:39
    
For one thing, $folder = "uploads/".$rand should read as $folder = "uploads/".$rand;. Missing ending ;. Plus you have no action= set for your form, unless you're using Ajax. –  Fred -ii- Jul 27 '13 at 14:41

2 Answers 2

up vote 2 down vote accepted

You have miss ; in many lines complete code:

if ( $ready == "false" ) { 
  $rand =  chr(rand(97, 122)). chr(rand(97, 122)). chr(rand(97, 122)); 
  $folder = "uploads/".$rand ;
}

if ( !is_dir($folder) ) {
    $ready = "true";
}
if ( is_dir($folder) ) {
    $ready = "false";
}

if ( $ready == "true" ) {
  $that = "yes";
  mkdir("uploads/".$rand);
  $to = "uploads/".$_FILES["file"]["name"];
  move_uploaded_file($_FILES["file"]["tmp_name"], $to);
  echo "uploaded";
}
share|improve this answer
1  
Missed ; is several places. –  jeff Jul 27 '13 at 14:38
    
edit answer, @jeff –  Alessandro Minoccheri Jul 27 '13 at 14:39
1  
mkdir("uploads/".$rand); $to = "Uploads/" (uploads != Uploads). != << does NOT equal ;-) Major FAIL, depending if you're on Linux or Windows. –  Fred -ii- Jul 27 '13 at 14:47
    
Thanks for the correction, I haven't see it! @Fred –  Alessandro Minoccheri Jul 27 '13 at 14:49
    
@AlessandroMinoccheri You're quite welcome. –  Fred -ii- Jul 27 '13 at 14:50

you forgot a semicolon at the end of line 7. The statement is not complete, so the parser does not expect the curly bracket.

if ( $ready == "false" ) { 
    $rand =  chr(rand(97, 122)). chr(rand(97, 122)). chr(rand(97, 122)); 
    $folder = "uploads/".$rand ;
}
share|improve this answer
    
now you should know what that error message means. You're going to see it again a few times after you make this correction, so now you know how to fix it. –  twinlakes Jul 27 '13 at 14:39
    
Amongst many other bad syntax. The OP's code is literally S=T=I=T=C=H=E=D with errors. –  Fred -ii- Jul 27 '13 at 14:54
    
OP should check out en.wikipedia.org/wiki/Stepwise_refinement –  twinlakes Jul 27 '13 at 14:56
    
Exactly, as well as the link to PHP manual on the subject that I posted under his original post. –  Fred -ii- Jul 27 '13 at 14:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.