Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
附加和未附加的Php文件_Php - Fatal编程技术网

附加和未附加的Php文件

附加和未附加的Php文件,php,Php,我有密码 if(count($_FILES) > 0) { foreach($_FILES['fileAttach']['error'] as $status){ if($status === UPLOAD_ERR_OK) { $fname[] = $_FILES['fileAttach']['name'][$Ccount]; $tmp_path[] = $_FILES['fileAttach']['tmp_name'][$Ccoun

我有密码

if(count($_FILES) > 0) {
    foreach($_FILES['fileAttach']['error'] as $status){
        if($status === UPLOAD_ERR_OK) {
        $fname[] = $_FILES['fileAttach']['name'][$Ccount];
        $tmp_path[] = $_FILES['fileAttach']['tmp_name'][$Ccount];
        $ftype[] =  $_FILES['fileAttach']['type'][$Ccount];
        }
        $Ccount++;
    }
} else { $fname[] = "0"; $tmp_path[] = "0"; $ftype[] = "0"; } // this not working
然后我想在函数中使用变量

SendEmails($ReCEmail,$strSubject,$strMessage,$txtFormName,$txtFormEmail,$fname,$ftype,$tmp_path);
它一直工作到附加文件,但如果没有,我得到错误
注意:未定义变量:fname in。。。在线..

function SendEmails($vasia,$strSubject,$strMessage,$txtFormName,$txtFormEmail,$fname,$ftypes,$tmp_path) {

if(count($fname) == 0) 
        { code without variables $fname,$ftypes,$tmp_path } 
else {code with variables $fname,$ftypes,$tmp_path}
}

如何修复此问题?

在执行以下操作之前初始化$fname数组:

$fname = array();
if($status === UPLOAD_ERR_OK) {
通过在if后放置和回显,确认上传过程正常:

if($status === UPLOAD_ERR_OK) {
        echo "Upload Status: " . $status . "<br>";
        $fname[] = $_FILES['fileAttach']['name'][$Ccount];
if($status==UPLOAD\u ERR\u OK){
回显“上载状态:.$Status.”
“; $fname[]=$\u文件['fileAttach']['name'][$Ccount];
如果echo输出显示$status!=UPLOAD\u ERR\u OK,则$fname未初始化,因此出现未定义变量错误


如果上载失败,请创建另一个问题,其中包含该问题的相应代码段。

如果所有$\u文件均为错误,则文件数组将为零。因此将打印此错误

$fname[] = array();
$tmp_path[] = array();
$ftype[] = array();

    foreach($_FILES['fileAttach']['error'] as $key => $status){
        if($status === 0) {
        $fname[] = $_FILES['fileAttach']['name'][$key];
        $tmp_path[] = $_FILES['fileAttach']['tmp_name'][$key];
        $ftype[] =  $_FILES['fileAttach']['type'][$key];
        }
    }

      if(count($fname)==0)
     { $fname[] = "0";$tmp_path[] = "0"; $ftype[] = "0"; }
在你的功能改变

if(count(array_filter($fname)) == 0) 

在我的回答中,echo的输出是什么?同一个echo,没有区别。你是说:echo“Upload Status:”.$Status.“
”outputs“Upload Status:”?如果是,这意味着$Status为null或空,因此,如果($Status==Upload\u ERR\u OK)等于FALSE。接下来,$fname从未初始化,这就是为什么会出现未定义的变量错误。请发布用于设置$status变量的代码。如果没有加载文件,为什么计数($\u文件)=1?因为您是从表单上载文件,它将发送$\u文件['fileAttach']即使你不上传任何文件
if(count(array_filter($fname)) == 0)