0

我收到以下错误:

调用未定义函数 convertTextFile()

我如何调用该特定功能?

这是我的代码:

public function post_files()
{
    // $file = Input::file('file'); // your file upload input field in the form should be named 'file'
    $allowedExts = array("gif", "jpeg", "jpg","htm","html", "ppt","pptx","png","txt","pdf","doc","rtf","docx","xls","xlsx","bmp");

    if(isset($_FILES['image']['tmp_name']))
    {
        $i=0;
        foreach(Input::file('image') as $key => $file)
        { 
            $temp = explode(".", $_FILES["image"]["name"][$i]);
            $extension = end($temp); 
            $filename= $temp[0];
            $destinationPath = 'upload/'.$filename.'.'.$extension;
            $name=$filename.'.'.$extension; 

            if(in_array($extension, $allowedExts))
            {     
                if($_FILES["image"]["error"][$i] > 0)
                {
                    echo "Return Code: " . $_FILES["image"]["error"][$i] . "<br>";
                }

                $sql=Author::check_document_details_Call($name);
                $exist=$sql[0]->result;


                if($exist == "1")
                {
                    echo $filename." already exists.<br> ";
                }
                else
                { 
                    $uploadSuccess=move_uploaded_file($_FILES["image"]["tmp_name"][$i],$destinationPath);

                    if( $uploadSuccess )
                    {
                        if($extension=='txt')
                        {
                            convertTextFile($destinationPath,"uploads/".$filename.".html");
                           $filename=$extension.".html";
                        }

                       $document_details=Response::json(DocumentProperty::insert_document_property_Call($name,$destinationPath));
                       echo "Update   ".$name."   successfully!!<br>";
                    } 
                    else 
                    {
                        return Response::json('error', 400);
                    }
                }
            }

            $i++;
        }
    }
}


function convertTextFile($inputFileName,$outputFileName)
{
    convertTxtToHtml($inputFileName,$outputFileName);
}
4

2 回答 2

0

尝试

$this->convertTextFile()同样适用于其中的函数convertTxtToHtml

为什么不$this->convertTxtToHtml()直接从post_files函数内部调用,为什么要为一行代码创建一个新函数?

于 2013-08-14T13:57:29.663 回答
0

如果这是在您的oop标签建议的类中,则需要使用$this->convertTextFile().

您的方法还应该具有可见性属性,具体取决于访问方式。如果只在该类中调用它,请给它一个private可见性。

于 2013-08-14T15:05:16.913 回答