Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-20-2009, 04:34 PM Conditional include
Average Talker

Posts: 19
Name: Bob Jones
Trades: 0
I'd like to create a conditional include that will display content only if the include file is present.

Here's my include as it is scripted now:

PHP Code:
<?php
// import file
include("wp-content/plugins/stuff.inc");
?>
How would I add a conditional statement that would display nothing if stuff.inc is not present?

Thanks
slobjones is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-20-2009, 04:43 PM Re: Conditional include
Defies a Status

Posts: 1,606
Trades: 0
If stuff.inc exists as an empty file nothing will be displayed. If it has content that will be displayed.

If you try to include it and it does not exist you get the error message. @include might supress that message. I do not know for sure.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 06-20-2009, 05:36 PM Re: Conditional include
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
if(file_exists("wp-content/plugins/stuff.inc"))
{
     include(
"wp-content/plugins/stuff.inc");
}

//OR
@include("wp-content/plugins/stuff.inc"); 
It looks to me like you are writing a wordpress plugin. If this is the case, I suggest you include files like this:

PHP Code:
include(dirname(__FILE__) . 'stuff.inc'); 
Later versions of wordpress allow you to move the plugin directory so specifying it as wp-content/plugins/ will reduce compatibility.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-20-2009, 07:16 PM Re: Conditional include
Average Talker

Posts: 19
Name: Bob Jones
Trades: 0
Excellent answers.

Thanks to you both!
slobjones is offline
Reply With Quote
View Public Profile
 
Old 06-21-2009, 06:13 AM Re: Conditional include
Junior Talker

Posts: 4
Name: Scabro Cabroni
Trades: 0
An alternative to "file_exists()" - would be to use "is_file()" function which checks whether file name exists and whether the file is regular.
__________________

Please login or register to view this content. Registration is FREE
: :
Please login or register to view this content. Registration is FREE
: :
Please login or register to view this content. Registration is FREE

Last edited by Scabro; 06-21-2009 at 06:15 AM..
Scabro is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Conditional include
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21500 seconds with 12 queries