ファイルをアップロードするために CakePHP でヘルパーを開発していましたが、アクションで使用するとエラーが返されます。このエラーの意味はわかっています。コントローラーでヘルパーを呼び出そうとしpublic $helpers = array('Session', 'File', 'Html');
ましたが、同じことが起こります。どうすればいいのかわからない。エラー:
Fatal Error
Error: Call to a member function info() on a non-object
File: /Users/diakonosdigital/Drive Diakonos/Google Drive/eJersusalem/WWW/ejerusalem/branches/app/Controller/DashboardController.php
Line: 614
FileHelper.php:
$info['name'] = $File['name'];
$info['tmp'] = $File['tmp_name'];
$info['ext']['mime'] = $File['type'];
$info['ext']['ext'] = $typeq[1];
$info['size']['b'] = $File['size'];
$info['size']['kb'] = $File['size'] / 1024;
$info['size']['mb'] = $info['size']['kb'] / 1024;
$info['error'] = $File['error'];
$info['hashed_name'] = $nname;
if($getHashed):
return $info['hashed_name'];
else:
return $info;
endif;
}else{
return "A file was not specified.";
}
}
/**
* Função responsável pelo upload dos arquivos
* @author Gabriel Cavalho
* @param $File file required - Deve prover todos os índices que o campo 'file' oferece, tmp_name, name, etc.
* @param $Options array required - Deve ser um array contendo as opçoes do upload, como o caminho de upload (path), se o nome deve ser 'hashed'
*/
public function upload($File, $Options){
if(isset($File) && isset($Options)){
if($Options['hash']){
$File = $this->info($File);
}
if(empty($Options['path'])){
$Options['path'] = WWW_ROOT . 'files' . DS;
}
if($Options['hashname']){
$File['name'] = $File['hashed_name'];
}
if($File['size']['mb'] > 5){
$File['error'] = 5;
}
if($File['error'] == 0){
/**
* No caso de não haver erros nenhum, essa parte é entrada em ação.
*/
if(move_uploaded_file($File['tmp'], $Options['path'] . $File['name'])){
return true;
}else{
return "An error has ocurred while uploading file.";
}
}else{
switch ($File['error']) {
case 1:
return "The file size exceeds the size provided by php.ini file";
break;
case 2:
return "The file size exceeds the size provided by the form (MAX_FILE_SIZE)";
break;
case 3:
return "The file wasn't fully uploaded";
break;
case 4:
return "No file was uploaded";
break;
case 5:
return "The file wasn't upload successfuly, the file size exceeds 5MB";
break;
case 6:
return "Missing tmp folder";
break;
case 7:
return "Failed in attempt to write file to disk";
break;
default:
return "Failed to upload file";
break;
}
}
}else{
return "Please, provide valid \$File and \$Options";
}
}
}
?>
エラーがある行:
$this->request->data['MainSlider']['slide'] = $this->File->info($this->data['MainSlider']['slide_file'], true);