Jump to content

Is There An Alternative To Include Or Perhaps Another Way Of Thinking About This Issue?


kjetterman

Recommended Posts

Here is the code that I wrote:

 

$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br />". include('testsite/includes/usermain/successpage.php') ." ";

 

The problem is, it is throwing an error because of this line: include('testsite/includes/usermain/successpage.php')

 

Here are the errors:

 

Warning: include(testsite/includes/usermain/successpage.php ) [function.include]: failed to open stream: No such file or directory in /home/xxxx/public_html/testsite/photog_main.php on line 1976

 

Warning: include() [function.include]: Failed opening 'testsite/includes/usermain/successpage.php ' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxx/public_html/testsite/photog_main.php on line 1976

 

From what I have read, this is a php.ini issue. So, I will need to change the server settings to Allow_url_include = yes and allow_url_fopen = yes. I can do this but I understand that to make these changes means a security risk. Is there anyway around this?

 

TIA for any help or guidance you can offer! :)

Link to comment
Share on other sites

From what I have read, this is a php.ini issue. So, I will need to change the server settings to Allow_url_include = yes and allow_url_fopen = yes.

Nope. The problem is what's stated in the error message: "No such file or directory". Since the script is in testsite/ you told PHP to look for the file in testsite/testsite/includes/usermain/successpage.php...

 

[edit] As for the INI settings, allow_url_include is a problem and you should never use it. However allow_url_fopen is very useful to have so do enable that, and actually by itself it's hard to use insecurely.

Edited by requinix
Link to comment
Share on other sites

requinix, thank you for your response!! :)

 

I changed the code slightly. I took off /testsite/includes on the url and now have includes/usermain...

 


$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br />". include('includes/usermain/successpage.php') ." ";  

 

I get this error...

 

Warning: include(includes/usermain/successpage.php ) [function.include]: failed to open stream: No such file or directory in /home/xxxx/public_html/testsite/photog_main.php on line 1976

 

Warning: include() [function.include]: Failed opening 'includes/usermain/successpage.php ' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxx/public_html/testsite/photog_main.php on line 1976

Link to comment
Share on other sites

Thank you for your response, Jessica! :)

 

Yes, I put the file in the includes/usermain folder on the server. Here is the path: http://diocesan.com/...successpage.php

 

$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br />". include('home/xxxx/public_html/testsite/includes/usermain/successpage.php') ." "; 

 

I get this error message:

 

Warning: include(home/xxxx/public_html/testsite/includes/usermain/successpage.php ) [function.include]: failed to open stream: No such file or directory in /home/xxxx/public_html/testsite/photog_main.php on line 1976

 

Warning: include() [function.include]: Failed opening 'home/xxxx/public_html/testsite/includes/usermain/successpage.php ' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/xxxx/public_html/testsite/photog_main.php on line 1976

 

I tried changing the url in the code to this also -- /home/xxxx/public_html/testsite/includes/usermain/successpage.php

 

Got the same errors above but just with the '/' in front of "home" (if that makes sense).

Edited by kjetterman
Link to comment
Share on other sites

Is the photog_main.php file being mentioned in the error the actual main file being requested? Or is it something like yourdomain.com/index.php and index.php is including photog_main.php?

 

The reason I ask is that relative include files are relative to the main file (the current working directory) and not a file that has been included itself.

 

Also, did you replace the xxxxx with your actual dioce2 path (btw these are NOT url's, they are file system paths.)

Link to comment
Share on other sites

Maybe this is a stupid question, but I see you are using the include() within a string concatenation for an assignment. You "can" create an include file to return data, but that is not a very common use of include files. So, did you set up that include file to "return" data rather rather than "echoing" it? If not, it will not work how you expect it - once you get the errors resolved.

Edited by Psycho
Link to comment
Share on other sites

Maybe this is a stupid question, but I see you are using the include() within a string concatenation for an assignment. You "can" create an include file to return data, but that is not a very common use of include files. So, did you set up that include file to "return" data rather rather than "echoing" it? If not, it will not work how you expect it - once you get the errors resolved.

 

Agreed. I am assuming she will be echo'ing $statusMessage at some point.

 

@kjetterman:

 

The basic logic for returning a "success" page could be the following:

 

if (something was successful) {
   include('successpage.php');
} else {
   include('error_page.php');
}

 

That is extremely basic, pseudo code. But since you are not going that path, why don't you not include the success page and just code it inline, within the $statusMessage variable? Looks like your successpage.php is only a few lines of code, anyway.

Link to comment
Share on other sites

Thanks for all of the help everyone! I really appreciate it! :)

 

Here's a puzzle (well for me... maybe not for you guys...lol )

 

$statusMessage is a variable used for many strings. Here is what I am talking about:

 

$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br />". include('includes/usermain/successpage.php') ." ";

}

}
else
$statusMessage = "<fieldset><img src=\"dImages/fail.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Error!</b></font><br>There was an internal error while trying to upload the file, please try again.</b></fieldset>";
}
else
$statusMessage = "<fieldset><img src=\"dImages/fail.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Error!</b></font><br>There was an internal error while trying to upload the file, please try again.</b></fieldset>";
}
else
$statusMessage = "<fieldset><img src=\"dImages/fail.gif\"> <font color=\"#CC0000\" size=\"3\"><b>The selected file is too small.</b><br>Use the Browse... button to select the file you would like to send.</font></fieldset>";
}
echo $statusMessage;

 

Now, if I structure the code like this:

 


$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br />";

include('includes/usermain/successmessage.php');

}

 

It works but is positioned below the $statusMessage string. So, the problem is in the positioning. I want the image (which is basically what is contained in successmessage.php), to be at the end of the first $statusMessage string but in between the quotes so that it will position below the string visually on the site. So the status message string needs to come first and then the image.

 

Does that make sense? I don't believe I can upload an image yet, otherwise I would give you a visual of what I am talking about.

Edited by kjetterman
Link to comment
Share on other sites

As I mentioned, you could just simply add the image to the existing $statusMessage variable, like so:

 

<?php
$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br /><a href=\"holidaycalendar.php\"><img src=\"/images_common/web_cal_christmas_2012.png\" alt=\"Christmas Calendar\" /></a><a href=\"/files_common/MI_cal_2012.pdf\"><img src=\"/images_common/print_button2.gif\" width=\"560\" height=\"37\" border=\"0\" style=\"margin-bottom: 20px;\" /></a>";

Link to comment
Share on other sites

As I mentioned, you could just simply add the image to the existing $statusMessage variable, like so:

 

<?php
$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.</fieldset><br /><a href=\"holidaycalendar.php\"><img src=\"/images_common/web_cal_christmas_2012.png\" alt=\"Christmas Calendar\" /></a><a href=\"/files_common/MI_cal_2012.pdf\"><img src=\"/images_common/print_button2.gif\" width=\"560\" height=\"37\" border=\"0\" style=\"margin-bottom: 20px;\" /></a>";

 

That is what I ended up doing. It was much easier that way and less hassle! I think ... I was making things harder than they needed to be. :idea:

 

Completed code:

 


$statusMessage = "<fieldset><img src=\"dImages/success.gif\"> <font color=\"#CC0000\" size=\"3\"><b>Success!</b></font><br>Your file, <b>". $_FILES['bulletinFile']['name'] ."</b>, was successfully uploaded. Please use the form below if you need to upload another file.<br /><a href=\"http://diocesan.com/testsite/holidaycalendar.php\"><img src=\"/images_common/web_cal_christmas_2012.png\"></a><a href=\"http://diocesan.com/files_common/MI_cal_2012.pdf\"><img src=\"/images_common/print_button2.gif\"></a><br /></fieldset>";

 

Thank you to everyone who helped in this thread! My goal is to get better at this and learn everything I can. So again, thank you all for being awesome!! :)

Edited by kjetterman
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.