2009-12-18 118 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