意外的T_BOOLEAN_OR

can*_*ail -3 php

我收到此代码的错误.我是PHP的新手,但我的理解||是将其翻译为'OR'.我试图检查上传的文件是否满足三个条件中的任何一个,如果是这样设置错误.

if ($uploaded_size > 1048576) || 
   ($uploaded_type == 'application/octet-stream') || 
   (file_exists($target))
{ 
    echo "Error: File was not uploaded.<br>"; 
    $ok=0; 
} 
Run Code Online (Sandbox Code Playgroud)

该错误表明"意外的T_BOOLEAN_OR"

Rei*_*ica 5

if ($uploaded_size > 1048576) ||
Run Code Online (Sandbox Code Playgroud)

请注意,您在之前if使用a 结束语句,因此它只是自己坐在外面.你也错过了和之间的括号.)||||(file_exists($target)) {

你可能想要这个:

if (($uploaded_size > 1048576) || 
    ($uploaded_type == 'application/octet-stream') || 
    (file_exists($target)))
{
Run Code Online (Sandbox Code Playgroud)

或等效的:

if ($uploaded_size > 1048576 || 
    $uploaded_type == 'application/octet-stream' || 
    file_exists($target))
{
Run Code Online (Sandbox Code Playgroud)