Raf*_*fee 0 php file-extension cakephp file-upload cakephp-2.1
I am using cakephp 2.1 and i am trying to upload files and how can i retrive the extension of the file.
Id Auto_Increment
username
file_name
Run Code Online (Sandbox Code Playgroud)
public function register(){
if ($this->request->is('post')){
$filename = $this->data['User']['file_name']['name'];
//$temp_ext = $this->data['User']['resume_file']['ext'];
$this->Session->setFlash('Extension : ' . $temp_ext);
}
}
Run Code Online (Sandbox Code Playgroud)
When tried the above code, to get extension. it only gives single letters like L, r ie firt character of the filename but not extension
Now how can i get the extension of the file.. i gone through this link
http://api.cakephp.org/class/file
Run Code Online (Sandbox Code Playgroud)
but could not understand to retrieve the file.
Adding a Debug report to @Julian Hollmann
array(
'User' => array(
'file_name' => array(
'name' => '550992_234300256686731_213914803_n.jpg',
'type' => 'image/jpeg',
'tmp_name' => 'D:\xampp\tmp\php866F.tmp',
'error' => (int) 0,
'size' => (int) 42292
)
)
)
Run Code Online (Sandbox Code Playgroud)
首先,您的数据应该在 $this->request->data
如果你想看看里面有什么,那就去做吧 debug($this->request->data);
编辑: 正确答案是:
$filename = $this->request->data['User']['file_name']['name'];
$extension = pathinfo($filename, PATHINFO_EXTENSION);
Run Code Online (Sandbox Code Playgroud)
另见php手册
| 归档时间: |
|
| 查看次数: |
7452 次 |
| 最近记录: |