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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失