我收到以下错误:
调用未定义的函数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);
}
答案 0 :(得分:0)
尝试
$this->convertTextFile()
同样适用于convertTxtToHtml
内的函数。
为什么不直接从$this->convertTxtToHtml()
函数中调用post_files
,为什么要为一行代码创建一个新函数?
答案 1 :(得分:0)
如果这是在您的oop
标记建议的类中,则需要使用$this->convertTextFile()
调用该函数。
您的方法还应具有可见性属性,具体取决于访问方式。如果仅从该类中调用它,则为其提供private
可见性。