How can i check if a path points to a folder or a file?
I'm building a small class for my zend application (using MVC). This class receive either a folder path or a file path. If its a folder path, i want to list all the files in that folder to make them downloadable. If its a file i want to make a single link to this file to make it downloadable.
The file/folder i'm pointing to is /zendApplicationName/Public/Models/Subfolder/File.
i tried to check开发者_如何转开发 using
is_file('pathToFile')
and
is_dir('pathToFolder')
to check the path that i build using
APPLICATION_PATH . '..\public' . $this->_path . 'file.docx'
and
$this->_baseUrl' . $this->_path . 'file.docx' // i took the baseURL from Zend_Controller_Front::getInstance()
I also tried to use the old school php version
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https'?'https':'http';
$path = $protocol . '://' . $_SERVER['HTTP_HOST'] . $this->_baseUrl . $this->_path . 'file.docx'
Thanks in advance
EDIT :
The problem is that even if the folder and the file exists, both function return false
Thanks for you comments, both where really useful. They made me recheck my code and the path was wrong
final path output is:
C:\wamp\www\elul\trunk\elul\application/../public/models/feuilleDeRoute/
using :
APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public' . $this->_path;
This way both can be checked, the folder and the file
精彩评论