dongxie5698 2014-07-10 09:33
浏览 45
已采纳

cakePHP:从tmp_name中提取没有文件路径的文件名

In my cakePHP Model i'm trying to use a custom validator to move file to new location an check its success. the custom method is:

    //custom method to check image
public function processCoverUpload($check = array()) {
    if (!is_uploaded_file($check['issue_cover']['tmp_name'])) {
        return FALSE;
    }
    if (!move_uploaded_file($check['issue_cover']['tmp_name'], WWW_ROOT . 'img' . DS . 'uploads' . DS . $check['issue_cover']['tmp_name'])) {
        return FALSE;
    }
    $this->data[$this->alias]['issue_cover'] = 'uploads' . DS . $check['issue_cove']['tmp_name'];
    return TRUE;
}

however $check['issue_cove']['tmp_name'] returns file name including its path. This will lead to wrong path string in move_uploaded_file. So how can i have only file name out of 'tmp_name'?

sample

$check['issue_cove']['tmp_name'] is F:\xampp\tmp\phpF765.tmp but i want phpF765.tmp only.

  • 写回答

1条回答 默认 最新

  • dtzh131555 2014-07-10 09:44
    关注

    Here is one way - probably nicer ways though :-)

    $fname = end(explode('\\',$check['issue_cover']['tmp_name']));
    

    $fname should now have the string you want.

    ps assumed it should be issue_cover and not issue_cove so change if my assumption was incorrect!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)