By MadKad on
I am using the newest version and I have my conetnt type set to php, but when I try and use
include('folder/file.php');
it just shows blank I have also tried include('file.php');
in the same folder root or path.
does anyone know what this could be?
Comments
To get my include to work, I
To get my include to work, I had to pass it a URL, not a filename. I know it shouldn't do that, but it did to me. Anyone else experience this?
That's what it's supposed to do
That's what it's supposed to do. You don't have it displaying anything. It's just including the file. It doesn't even run any functions from that file, unless the functions are called.
Mike
Edit:
Are you getting a php error because you're calling a function from the included file, and it's not finding it?
Yeah But !!!
If the file contains any kind of Text or legitimate HTML directives. Something should be displayed, should it not?
No.
No. Include files are for holding functions that can be used on multiple pages. If you opened, read, and then parsed the included file, sure, that would work. But the way you're doing it... Not so much.
What, exactly are you trying to do? Maybe there's a better way around that I can suggest.
Mike
I tried the full url and
I tried the full url and that didnt work also, and the file contains a script but a script that will print so it should show something, but I also tried this with a htm file with just text in and there was still no luck.
It looks like to me there is a bug in the new version?
the pages are scripts that run inside there selfs and desplay the content within the same file, but they do include other files within there scripts.
What's your function called?
Put your script into a function and call the function.
Or something like that.
Mike
the function is
the function is just
as its a webmaster tool and I want to add these tools into my drupal pages
but
isnt working and it did in the older versions i used?
is this another subject that
is this another subject that isnt going to be sorted, come on some body must have the same problem and got theres working. It has to be a bug!!
It needs to be called.
I'm telling you, just because you're including the file, doesn't mean that any of the functions or tools within that file are being called. Test it out.
Mike
OK
OK I have just tested it on my other drupal that is an older version and its fine, and I called the same script, there are some bugs in the script that isnt a problem but drupal is look:
this is the correct one
http://www.mkpitstop.co.uk/forum/blogs/?q=test
and this is the one that isnt working
http://www.mkpitstop.co.uk/?q=test
I have found that its something to do with the way the page renders as in the filter section on the php when i play with these filters I get different views but its not letting all the php work, also it even says
"Because of the flexible filtering system, you might encounter a situation where one filter prevents another from doing its job. For example: a word in an URL gets converted into a glossary term, before the URL can be converted in a clickable link. When this happens, you will need to rearrange the order in which filters get executed."
so looks like it is a bug with the new version.
Reference...
Let's stop the speculation:
http://www.php.net/manual/en/function.include.php
include includes and evaluates the file. If the OP just has functions in there, then sure ,they have to be called. However, if the include file has output such as :
then it should display.
to the OP: Does your include path contain the current directory ( ".") ?
ok thanks
So it is a bug with drupal latest version then?
I really need to be able to use this
Works for me
I keep various include files in a subdirectory of the Drupal includes directory so the HTML/PHP can be version controlled rather than living in the database.
eg:
Try using the './' on the front of the path.
--
Anton
New to Drupal? | Forum posting tips | Troubleshooting FAQ
Finally, a solution.
Just to confirm, you have to use the ./ at the front of the path. I just spent an hour trying to figure out why my includes stopped working. It seems to work without the ./ on Drupal 5.1, but needs it on Drupal 5.7.
I realize this is an old post, but I figure it might help others at some point.
______________________________________________________________________________________________________
mybesinformatik.com - Drupal website development
______________________________________________________________________________________________________
Thanks
Thanks, I was actually just trying to find that out!
Your solution worked for me
Your solution worked for me using Drupal 6. Had to include a php file into the content area for displaying some dynamic content.
./ is the key
lol cant believe this thread
lol cant believe this thread still gets dam posts but I cant get help with other things, drupal is bad
This is a better way
The code snippet below worked for me and is better in that it creates an absolute path to the root of your drupal installation, which will migrate to other servers when moved, and concatenates it with whatever path you use to hold your php file.
You can also use include_once, require, and require_once too.
Thanks
Thanks guys this helped me!
A better (for Drupal) solution
As a 14 year veteran of PHP programming, this was a terribly frustrating issue for me. A PHP file include is not a complicated issue. It's ridiculously easy. I tried all of the above solutions, and came up with nothing. Even the above solutions shifted as versions of Drupal change.
I know this is listed as a ver 4.7 issue, but Google kept bringing me back to this page and after four days, it finally clicked for me.
So I'm sharing this solution to save you all the bottles of aspirin in getting something that's basic PHP to work in Drupal. This would apply to all the above versions of Drupal, works for D7 and will probably work for D8 which is being released now. The solution:
Create a module.
It's a really simple process, and although it makes no sense from a logical programming standpoint, where the file should just be able to be included in a theme file (or wherever), Drupal was designed to discourage logical and simple programming. For those that do not know how to create a module, it's simple.
1) In the directory drupal/modules create a directory with your module name. For this example, I will use teacup. So my directory is drupal/modules/teacup/
2) In the teacup directory, create a new file. This is teacup.info
3) Add the following to your teacup.info file:
Naturally, if you are using Drupal 6, you would have the core as 6.x. And yes, use the 'x' in your info file. Now save.
4) Create another file inside the teacup directory called teacup.module. While its a .module file, it's really just a .php file. Any code, functions, classes (etc) that you want to use, you will place in this file.
5) Go to your administration area and under modules scroll down to where you find the listing for the Tea Cup module. Click the box to activate the module, and then save modules.
6) Enjoy a cup of coffee. You're done.
Now you can place any code you want in the .module file for use in any place in your site. You can add functions and/or classes that can be called from inside content or other template files. I also could not get functions inside template.php to trigger as expected, and this also solved that problem.
Additionally, if you were hoping to include other libraries you can easily do that now, as well, by simply placing an include("file.php") inside your teacup.module file, as you would normally expect a file include to work. Sadly it took this much work to get to where we should have been at the beginning, but at least we got there.
Some important notes
1) Open your PHP files normally, with the PHP opening tag, but not the closing tag.
Closing your .module or .php files with this can cause the Drupal installation to break on certain server configurations.
2) All the file and directory names must be consistent. Where I used teacup, you can use any name you like, even teacup, but they must all be identical. For instance, if you wanted to name your module "milkbone":
The directory would be drupal/modules/milkbone
The info file would be milkbone.info
The module file would be milkbone.module
3) If you use this technique in a different version of Drupal, or you build your own handy module of your favorite libraries and snippets and migrate it to a new version, remember to change the core number in the .info file to match the version of Drupal you want to use it with. Also check the documentation on authoring modules for your version of Drupal to make sure critical changes to the format will not cause your module to fail.
When I get a little time, I will pre-package blank versions of these modules for download on my own website for all versions of Drupal to make life even a little easier. Or if someone knows of a source for this at present, they could post a link (thank you in advance to anyone that does).
All in all, this is a relatively simple process and should solve all of your file include issues in the future. Hope this helps a lot of people!