Query returning defafult path to file in database
Permalink 1 user found helpful
I am trying to pull an image from the database called 'background.png'. When this image exists in the database, I want it to be set as the background of my site, however, I am unable to get the actual path to the image. When I run the following:
I receive the following path: /home3/fuzedmar/public_html/sb/files/ , which is the default path to the file manager instead of the full path to the image in question. I know I am pulling the ID of the image correctly as I have echoed the $result variable, but it seems that is not working. Any help would be greatly appreciated. Or if there is a better solution that someone can offer. Thanks in advace
I receive the following path: /home3/fuzedmar/public_html/sb/files/ , which is the default path to the file manager instead of the full path to the image in question. I know I am pulling the ID of the image correctly as I have echoed the $result variable, but it seems that
File::getByID($result);
I am still not getting the correct path:
I am getting:
http://sb.fuzedmarketing.com/files/... as the path instead of what it should be:
http://sb.fuzedmarketing.com/files/9413/0143/9102/background.png...
Not sure why I'm getting that.
function imgXplosion() { $f = Loader::model('file'); $db = Loader::db(); $result = $db->query("SELECT fID FROM `FileVersions` WHERE fvFilename = 'background.png'"); $result = trim($result, "fID .. "); $result = rtrim($result); $fileUrl = File::getByID($result)->getVersion()->getUrl(); return $fileUrl; }
I am getting:
http://sb.fuzedmarketing.com/files/... as the path instead of what it should be:
http://sb.fuzedmarketing.com/files/9413/0143/9102/background.png...
Not sure why I'm getting that.
Update:
Thank you very much ScottC for your information above. I figured out that the problem was with typecasting. I was trying to pass a string to the getUrl method, so after typecasting it to int, the function does exactly what I intended. Thanks again.
Then passed that to the getUrl method
Thank you very much ScottC for your information above. I figured out that the problem was with typecasting. I was trying to pass a string to the getUrl method, so after typecasting it to int, the function does exactly what I intended. Thanks again.
$result = (int)$result;
Then passed that to the getUrl method
Loader::model('file');
//url
$fileUrl = File::getByID($fID)->getVersion()->getUrl();
//path
$filePath = File::getByID($fID)->getVersion()->getPath();
the path is the system path which you don't really use in css stuff, its more if you want to call getimagesize or something where you either need the path or a pointer to the file in the system.
Hope that helps. you definitely want the url and not the path :)