이 오류 원인을 알아낼 수 없습니다PHP T_Public 구문 오류?
Parse error: syntax error, unexpected T_PUBLIC
그것은 오류가이 코드 (public function upload($uid = 'public')
의 두 번째 줄에 발생하는 있다고 말했습니다.
//--> Uploads the file
public function upload($uid = 'public')
{
//Get file details
if(isset($_GET['ajax']))
{
if(!$_SERVER['HTTP_X_FILE_SIZE'] > 0) return false;
$filename = strip_tags($_SERVER['HTTP_X_FILE_NAME']);
$file_type = $_SERVER['HTTP_X_FILE_TYPE'];
$size = round($_SERVER['HTTP_X_FILE_SIZE']/1000, 3);
}
else
{
if($_FILES["files"]["error"] > 0 or empty($_FILES)) return false;
$filename = strip_tags($_FILES['files']['name']);
$file_type = $_FILES['files']['type'];
$size = round($_FILES['files']['size']/1000, 3);
}
//FF null type fix
if($file_type == null || strlen($file_type) == 0) $file_type = "unknown";
//Reduce filename to < 255 char
if(strlen($filename) > 255)
{
$filename = urldecode($filename);
$filename = substr($filename, 0, 36) . '--.' . pathinfo($filename, PATHINFO_EXTENSION);
$filename = urlencode($filename);
}
//Check file size
if($size > (maxFileSize/1000))
{
$this->errorMessage = "file too large";
return false;
}
//Check file type
if(limitFileTypes and !in_array($file_type, explode(',', allowedFileTypes)))
{
$this->errorMessage = "file type not allowed";
return false;
}
$db = $this->connectDB();
$share = isset($_GET['ajax'])?$_SERVER['HTTP_BITDROPSHARE']:$_POST['bitdrop_share'];
$share = ($share == 'true' || $share == 'share')? 1 : 0;
$password = isset($_GET['ajax'])?$_SERVER['HTTP_BITDROPPASS']:$_POST['bitdrop_password'];
//Find an available shortURL
$res = $db->prepare("select count(shortURL) from share where binary shortURL = ?;");
do
{
$shortURL = $this->shortURL();
$res->execute(array($shortURL));
$data = $res->fetchAll(PDO::FETCH_COLUMN, 0);
}
while($data[0] != 0);
$password = (is_null($password) or strlen($password)==0) ? 0 : sha1($password . $shortURL) ;
$q = "insert into details (date, name, size, type, public, password) values (now(), ?, ?, ?, ?, ?)";
$data = array($filename, $size, $file_type, $share, $password);
$res = $db->prepare($q);
//exec command or print error
if(!$res->execute($data)) print_r($db->errorInfo());
$fid = $db->lastInsertId();
$q = "insert into share (shortURL, file_id) values (?, ?)";
$data = array($shortURL, $fid);
$res = $db->prepare($q);
$res->execute($data);
//Connect unique user to file
$tid = $this->addTag("_$uid");
$q = "insert into `fid-tid` (file_id, tag_id) values ('$fid', '$tid');";
$res = $db->prepare($q);
$res->execute();
$file = $_SERVER[DOCUMENT_ROOT] . "/uploads/$fid.temp";
$this->log('upload', '{ "uid" : "'.$uid.'", "fid" : "'.$fid.'", "shortURL" : "'.$shortURL.'" }');
$db = null;
//Upload file
if(isset($_GET['ajax']))
{
if(!isset($_SERVER['HTTP_X_FILE_NAME']) && !isset($_SERVER['CONTENT_LENGTH']))
{
$this->errorMessage = "no headers found";
return false;
}
$fileReader = fopen('php://input', "r");
$fileWriter = fopen($file, "w+");
while(true)
{
$buffer = fgets($fileReader, 4096);
if(strlen($buffer) == 0)
{
fclose($fileReader);
fclose($fileWriter);
$this->createThumb($fid, $shortURL);
$this->shortURL = $shortURL;
return true;
}
fwrite($fileWriter, $buffer);
}
}
else
{
move_uploaded_file($_FILES["files"]["tmp_name"], $file);
$this->createThumb($fid, $shortURL);
$this->shortURL = $shortURL;
return true;
}
}
아싸! 당신의 들여 쓰기가 어떻게 되었습니까? ':-)' – halfer
다음 번에는 최소한의 예제를 만들 수 있는지 확인하십시오. 귀하의 경우, 당신은 다음과 같은 예제를 만들 수 있습니다 :'public function test() {echo 'test';}'.. 당신은 여전히 오류를 얻고 질문은 훨씬 더 명확해질 것입니다. 대답은 '대중'이 거기에 허용되지 않기 때문에 당연히 흥미롭지는 않겠지 만 더 나은 질문을하기에 좋은 단계 일 것입니다 :) – Nanne
고전적인 부분 복사 + 붙여 넣기처럼 보입니다 (비록 다른 구문이 될 수 있지만 문제). Origin, btw :'bitdrop.class.php - v1.4'. – mario