-4

使用我的 php 代码时出现此错误

PHP 语法检查:解析错误:语法错误,第 7 行代码中出现意外的“}”

请帮助我,我不明白我在这里做错了什么 php 代码:

<?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>
4

2 回答 2

1

你错过;了很多行完整的代码:

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";
}
于 2013-07-27T14:36:44.030 回答
1

您忘记了第 7 行末尾的分号。该语句不完整,因此解析器不需要大括号。

if ( $ready == "false" ) { 
    $rand =  chr(rand(97, 122)). chr(rand(97, 122)). chr(rand(97, 122)); 
    $folder = "uploads/".$rand ;
}
于 2013-07-27T14:38:14.487 回答