php not finding folder
Permalink
Hello. I am new to both C5 and PHP, so maybe my problem will be easily answered by you experts here.
I am converting a static site to C5, so am in the process of building a custom theme. So far it is all working well, with the following exception:
One of my html pages (now a .php page) has a chunk of php code in it. This php scans a folder and pulls in any image files in the folder and places them into my custom photo gallery. This all works fine on my local machine running WAMP (but I don't have C5 installed locally). However, on my host in C5 the php produces a warning
"opendir(/conc/themes/3mg/images/photos/) [function.opendir]: failed to open dir: No such file or directory".
However, that path shown does exist and has my images in it.
BTW, the variable set for the path is done as follows:
$images_dir = $this->getThemePath() . '/images/photos/';
I should note also that throughout my other files or in other html elements within this file, references to folders using "<?=$this->getThemePath()?>/some_folder/some_file" works fine.
One other question: Is it OK in C5 to run php code within the html/php file, or should the php code be placed in a single page file (now sure how to attempt this)? I would prefer to leave it as is for now if it can work.
Any thoughts would be greatly appreciated.
I am converting a static site to C5, so am in the process of building a custom theme. So far it is all working well, with the following exception:
One of my html pages (now a .php page) has a chunk of php code in it. This php scans a folder and pulls in any image files in the folder and places them into my custom photo gallery. This all works fine on my local machine running WAMP (but I don't have C5 installed locally). However, on my host in C5 the php produces a warning
"opendir(/conc/themes/3mg/images/photos/) [function.opendir]: failed to open dir: No such file or directory".
However, that path shown does exist and has my images in it.
BTW, the variable set for the path is done as follows:
$images_dir = $this->getThemePath() . '/images/photos/';
I should note also that throughout my other files or in other html elements within this file, references to folders using "<?=$this->getThemePath()?>/some_folder/some_file" works fine.
One other question: Is it OK in C5 to run php code within the html/php file, or should the php code be placed in a single page file (now sure how to attempt this)? I would prefer to leave it as is for now if it can work.
Any thoughts would be greatly appreciated.
Yes, I agree that ultimately the file manager should be used for this, and I would expect my client to in fact use that to upload their photos. However, at the moment, since I simply haven't had a chance to come up to speed on so many things in C5, I figured I'd do some testing just using a normal folder structure like I'm used to. I would still like to know why my php thinks that folder within my theme doesn't exist.
As for the gallery, I really need to use my own, as the client requires the photos be displayed in a very specific manner and with specific placement, etc. That part is a no-brainer, I just need to figure out how to get my gallery to see the photos (in a folder or in the file manager).
Based upon your response, I will indeed investigate file sets to see how I might employ them.
Thanks for your reply.
As for the gallery, I really need to use my own, as the client requires the photos be displayed in a very specific manner and with specific placement, etc. That part is a no-brainer, I just need to figure out how to get my gallery to see the photos (in a folder or in the file manager).
Based upon your response, I will indeed investigate file sets to see how I might employ them.
Thanks for your reply.
Try
$images_dir = $this->getThemePath('images/photos/');
Hmm... same warning. That produced "/conc/themes/3mg". So seemingly only the "base path" of images/photos.
I'm wondering if the leading "/" is proper for what is being returned in these paths. I guess that would still be considered relative to the root dir.
Thanks.
I'm wondering if the leading "/" is proper for what is being returned in these paths. I guess that would still be considered relative to the root dir.
Thanks.
Are you sure /conc/themes/3mg/images/photos/ exists?
I'm seriously doubting that your hosting provider has /conc/ as the DOCUMENT ROOT (it's possible, but unlikely).
If you are calling opendir() from a file in your theme directory you probably want something like opendir('3mg/images/photos/');
If that directory exists then it might be a permissions problem.
John
I'm seriously doubting that your hosting provider has /conc/ as the DOCUMENT ROOT (it's possible, but unlikely).
If you are calling opendir() from a file in your theme directory you probably want something like opendir('3mg/images/photos/');
If that directory exists then it might be a permissions problem.
John
John,
Yes, my php file in question here is in the themes directory. C5 is installed under public_html/, so the full path to that photos directory is: public_html/conc/themes/3mg/images/photos/. And yes, it really does exist.
I've tried various combinations of path formats, but can't get opendir() to see it.
Yes, my php file in question here is in the themes directory. C5 is installed under public_html/, so the full path to that photos directory is: public_html/conc/themes/3mg/images/photos/. And yes, it really does exist.
I've tried various combinations of path formats, but can't get opendir() to see it.
Just FYI,
<?php echo $this->getThemePath(); ?> returns "/conc/themes/3mg/"
<?php echo $this->getThemePath(); ?> returns "/conc/themes/3mg/"
If you put this code there, you will find that the path is *not* public_html/... but probably something more like /home/username/public_html/... /conc/3mg/
opendir() takes either a fully qualified path (starting with /) or relative to the current directory.
So you probably want this:
If it tells you the directory does not exist, it's probably doesn't :)
opendir() takes either a fully qualified path (starting with /) or relative to the current directory.
So you probably want this:
opendir('images/photos/');
If it tells you the directory does not exist, it's probably doesn't :)
Ah, jasteele123, you are correct. The working directory is shown as:
/home/edgwebde/public_html/conc
So when I use:
/home/edgwebde/public_html/conc/themes/3mg/images/photos/
as the path, now opendir() works. Note that simply using 'images/photos/' does NOT work. I should think it would.
However, that full path that opendir() likes is a problem, as when the <ul> gallery list is built, the urls such as:
"/home/edgwebde/public_html/conc/themes/3mg/images/photos/00238_after-W450.jpg"
are seen in a browser as:
"http://www.edgwebdesigns.com/home/edgwebde/public_html/conc/themes/3mg/images/thumbs/00238_after-W450.jpg"
Obviously you don't want the "home/edgwebde/public_html/" part seen from the browser.
Bottom line is that I'd like to use a relative path to my photo folder, but can't seem to get such a path to work.
Thanks so much to all of you for your patience with me. And sorry for the somewhat long convoluted post. I'll keep playing around with this...
BTW, feel free to check out the code at:http://www.edgwebdesigns.com/conc/index.php/photos/...
Note that this site is currently just a wireframe representation of what will eventually exist. For now everything there is just "placeholder" crap.
/home/edgwebde/public_html/conc
So when I use:
/home/edgwebde/public_html/conc/themes/3mg/images/photos/
as the path, now opendir() works. Note that simply using 'images/photos/' does NOT work. I should think it would.
However, that full path that opendir() likes is a problem, as when the <ul> gallery list is built, the urls such as:
"/home/edgwebde/public_html/conc/themes/3mg/images/photos/00238_after-W450.jpg"
are seen in a browser as:
"http://www.edgwebdesigns.com/home/edgwebde/public_html/conc/themes/3mg/images/thumbs/00238_after-W450.jpg"
Obviously you don't want the "home/edgwebde/public_html/" part seen from the browser.
Bottom line is that I'd like to use a relative path to my photo folder, but can't seem to get such a path to work.
Thanks so much to all of you for your patience with me. And sorry for the somewhat long convoluted post. I'll keep playing around with this...
BTW, feel free to check out the code at:http://www.edgwebdesigns.com/conc/index.php/photos/...
Note that this site is currently just a wireframe representation of what will eventually exist. For now everything there is just "placeholder" crap.
You should probably try this:
Sorry for the delay in replying, been off the 'net...
$images_dir - opendir('themes/3mg/images/photos/');
Sorry for the delay in replying, been off the 'net...
What might be easier is to use some of the things C5 is great with. File Sets
Upload whatever images you want into the file manager and then put them into a file set
on the page where you want those images to show, create a slideshow or gallery, there are a few that come free with C5, however, there are also some great add ons in the marketplace for some beautiful slideshows/galleries.
All of these add ons have an option to display all images within a file set.
Here is some documentation on file sets:
http://www.concrete5.org/documentation/using-concrete5/dashboard/fi...