2009-12-18 119 views
0

这工作:神秘,变量路径名

function upload($directory) { 
     App::import('Vendor', 'UploadedFiles', array('file' => 'UploadedFiles.php')); 

     echo $directory; 
     $this->_saveUploadedFiles('C:/xampp/htdocs/freetickets/app/webroot/img/gallery/zantje_11042/'); 
    } 

    function _saveUploadedFiles($galleryPath) { 

    $absGalleryPath = $galleryPath; 
    $absThumbnailsPath = 'C:\xampp\htdocs\freetickets\app\webroot\img\gallery\zantje_11042\thumbnails\\'; 

    //Iterate through uploaded data and save the original file, thumbnail, and description. 
    while(($file = UploadedFiles::fetchNext()) !== null) { 
     $fileName = $file->getSourceFile()->getSafeFileName($absGalleryPath); 
     $file->getSourceFile()->save($absGalleryPath . '/' . $fileName); 

     $thumbFileName = $file->getThumbnail(1)->getSafeFileName($absThumbnailsPath); 
     $file->getThumbnail(1)->save($absThumbnailsPath . '/' . $thumbFileName); 
    } 
    } 

但这并不:

 function upload($directory) { 
     App::import('Vendor', 'UploadedFiles', array('file' => 'UploadedFiles.php')); 

     echo $directory; //echoes C:/xampp/htdocs/freetickets/app/webroot/img/gallery/zantje_11042/ 
     $this->_saveUploadedFiles($directory); 
    } 

    function _saveUploadedFiles($galleryPath) { 

    $absGalleryPath = $galleryPath; 
    $absThumbnailsPath = 'C:\xampp\htdocs\freetickets\app\webroot\img\gallery\zantje_11042\thumbnails\\'; 

    //Iterate through uploaded data and save the original file, thumbnail, and description. 
    while(($file = UploadedFiles::fetchNext()) !== null) { 
     $fileName = $file->getSourceFile()->getSafeFileName($absGalleryPath); 
     $file->getSourceFile()->save($absGalleryPath . '/' . $fileName); 

     $thumbFileName = $file->getThumbnail(1)->getSafeFileName($absThumbnailsPath); 
     $file->getThumbnail(1)->save($absThumbnailsPath . '/' . $thumbFileName); 
    } 
    } 

唯一的区别$this->_saveUploadedFiles('C:/xampp/htdocs/freetickets/app/webroot/img/gallery/zantje_11042/')和一个具有可变的路径:$this->_saveUploadedFiles($directory);

那么,为什么它不使用$目录,即使$directory回声C:/ xampp/htdocs/freetickets/app/we broot/img/gallery/zantje_11042 /?

感谢

+0

非工作人员做什么? – danben 2009-12-18 19:12:16

+0

可能有些事情要做/图像。无论如何,我不认为使用绝对URL是一个好主意。在cake /的某处检查paths.php,它提供了几乎所有你需要的常量。 – Wayne 2009-12-19 04:11:03

回答

0

检查你已经把路/和\作为路径分隔符的文件夹。

+0

或者他可以使用DS常数。 – Wayne 2009-12-19 04:09:17