Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> phpnuke 7.6
Author Message
tommyb
Hangin' Around



Joined: May 31, 2006
Posts: 49

PostPosted: Thu May 24, 2007 9:47 am Reply with quote

Hi,

Wasn't too sure whereabouts to ask this question so here we go.

If i had a php page that was used to create an image: e.g

Code:


header("Content-Type:image/jpg");
header('Content-disposition:inline; filename="mypic.jpg"');
$im = imagecreatetruecolor(100,100);
$nim = imagecreatefromjpeg("image/dir/image.jpg")
imagecopyresampled($im,$nim,0,0,0,0,100,100,imagesx($nim),imagesy($nim);
imagejpeg($im);
imagedestroy($im)



How would I actually connect to the database using phps native functions. Say I had a gallery where users upload pics. They could be gif or jpg then the Content-Type would have to be dynamically created from the info stored in the db. Obviously I wont want to include header.php in this file. So do I include mainfile.php? add the globals of $db etc or is there another way to do this (without having to hardcode the database connection info into this file) so that it could be used in a global nuke sense as opposed to me running native SQL functions based on my db type.

Many Thanks
 
View user's profile Send private message
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Thu May 24, 2007 12:48 pm Reply with quote

If you create a new Nuke module that's modeled after one of the existing ones, it should automatically include what you need. This will include mainfile and config.php where your database connection information is stored. Then you use the object that's in /db/mysql.php as $db->sql_query($your_query). I can't say that I fully understand what you are trying to do, but that might help.
 
View user's profile Send private message Visit poster's website
tommyb







PostPosted: Thu May 24, 2007 1:11 pm Reply with quote

Thanks for replying. I understand how to create modules and i know that first i include mainfile and then on any page include header.php and that puts in the the header left, the links logo etc. If i had a page where users uploaded pictures and the destination folder was outside of the root I would then have to use php to dynamically display those images.

Now when someone uploads a file it could be a gif or a jpg for example and this info would be stored in the database.

Now say I have a page called image.php which creates a copy of the image outside the root using GD library. On this page I wouldn't want to include the header (as it contains logo etc so I wouldnt want this twice on the page). When I display the image back it would be something like
Code:
<img src=modules/mymodule/image.php?id=1 alt=alt text />


When the image.php gets the id it would then need to connect to the database and find out the mime type of the image with that id. Then running through if statements checking the mime type it would know whether to use image/jpeg or image/gif as the header. As a normal module page includes mainfile.php and header.php I can call the database functions. image.php would not have the header included as it would mess up the image creation and I have tried including mainfile.php with no luck. I know I could get my db info out of config.php and create something like

Code:


$dbc = mysql_connect(host,user,password blah blah.....

but then I am only using mysql (as opposed to the point of nuke supporting multiple database types) and I am unnecessarily duplicating my database info.

How can I get the image.php to just display the image it should but get info from a db as Icannot include the header and including mainfile.php does not seem to work?

Sorry if this post seems condesending in any way but i have just tried to explain it in full detail in a step by step kind of way.

Many Thanks
 
fkelly







PostPosted: Thu May 24, 2007 1:39 pm Reply with quote

You didn't sound condescending and you do sound knowledgeable. A problem with Nuke for you is that everything is so interweaved that if you use the standard Nuke approach you are almost certainly going to include header.php somewhere. It can be difficult to trace which file includes which other file. You might try just including config.php but you'd also almost certainly need /db/db.php which in turn will include mysql.php. However, certain paths are set up in mainfile and you might need these to find the right paths to the /db files, I'm not sure.

I would agree with you about avoiding duplication of database information. However, we've had some discussions about this in the past and it's not quite clear whether anyone is using another database than mysql with nuke.

Come to think of it, during the development of scripts for upgrading to rn2.10, Montego helped me with some code in the rndb_upgrade.php script that comes in the /installation folder of that distribution. It goes like this:

Code:


define('INSIDE_INSTALL', true);
require("../config.php");
require("../db/db.php");


You might have luck with some variant of this.
 
tommyb







PostPosted: Thu May 24, 2007 2:58 pm Reply with quote

I'll try including them and see if it works then. I'll let you know my results

Many thanks
 
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu May 24, 2007 3:27 pm Reply with quote

INSIDE_INSTALL works for RavenNuke, but given the path structure - you should use INSIDE_MOD. Also INSIDE_MOD is defined in normal phpNuke

Just use
Code:


define('INSIDE_MOD',true);
include("../../mainfile.php");

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
tommyb







PostPosted: Thu May 24, 2007 3:31 pm Reply with quote

Yeah its just normal nuke.

Many thanks Raven and fkelly
 
tommyb







PostPosted: Wed Jun 13, 2007 2:18 am Reply with quote

Hi Again,

I have tried the define('MODULE_FILE' ,TRUE) <- works for my version
and then include mainfile.php and this allows me to perform the queries.

If i was using the page to generate an image however the inclusion of mainfile throws this out. I'm presuming this is because mainfile echos out some html data, which,obviously when i then send an image header followed by imagegif for example, throws out the image in results in a broken image display. I believe this is down to the inclusion of mainfile as I have tried removing that line and including the db connection info in the same script and the images will display without a problem.

Does anybody have any ideas of a work around for this without me having to duplicate my db info?

Many Thanks

**edit tried including config.php and db.php and this throws it out as well
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Wed Jun 13, 2007 6:39 am Reply with quote

mainfile.php does not echo anything to the browser from what I can recall. The output is generally started by including header.php.

I also just verified it with a simple test.php script which does nothing but include mainfile.php.

So, some other code you have must be causing this. It is also possible that if you are getting an error (either PHP or mySQL) that it could be trying to write to the standard output, which can hose things up too. Even PHP warnings, depending upon the level of error reporting you have set, can do this. Just some things to look for.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
tommyb







PostPosted: Wed Jun 13, 2007 7:11 am Reply with quote

It works until I do a require_once('mainfile.php') and change the mysql_query to $db->sql_query (and remove db connection info) which is why i figured it has to be to do with mainfile.

I don't have access to a testing server though so i've uploaded the module to my site but it is admin only and as such I don't want to turn error reporting on.

Thanks for replying.
 
montego







PostPosted: Wed Jun 13, 2007 7:34 am Reply with quote

But, without turning on error reporting (you only have to do it for ONE simple quick test), we're not going to be able to help you much further. I am convinced that mainfile.php and these other files that get included do not echo anything, so it must be generating an error.
 
tommyb







PostPosted: Wed Jun 13, 2007 8:01 am Reply with quote

Just tried it and I get no errors displayed. They displayed in other areas so I know it isnt that the error reporting was disabled at server level. I've tried the require_once as mainfile.php and the direct path to it as well as the path from the account root and still no luck. ( i tried this as i thought, seen as the file is being called as an image it might need a direct path as it is not in the url as &file=myfile)

I looked through the mainfile and it is just functions that include echo statements but obviously the functions are just being created and not called so it shouldn't have any effect.
 
montego







PostPosted: Wed Jun 13, 2007 6:47 pm Reply with quote

Well, that is definitely odd. Lets us try to bypass mainfile.php. Do what fkelly said and instead of including mainfile.php, do this:

Make sure you are using something like this for the image tag (not exactly what you had):

<img src="http://yourdomain/modules/mymodule/image.php?id=1" alt="alt text" />

And instead of mainfile.php, use this:

require("../../config.php");
require("../../db/db.php");

Notice the slight deviation on the relative path.

Anything now?
 
tommyb







PostPosted: Mon Jun 25, 2007 3:55 am Reply with quote

Well I managed to get this work using the mainfile includes. When I was displaying the image I was doing it in the format
Code:


<img src="modules/mymodule/image.php?id=1" alt="meh" />

I replace this with
Code:


<img src="modules.php?name=mymodule&file=image&id=1" alt="meh" />

And this worked.

Just thought I'd share this info in case anyone else has a similar issue.
 
montego







PostPosted: Tue Jun 26, 2007 6:26 am Reply with quote

Well, that is the difficulty in trying to help someone when you have no idea what the module code is written like. Glad this is working.
 
tommyb







PostPosted: Tue Jun 26, 2007 7:03 am Reply with quote

Sorry about that I guess I should have posted the whole code up. Was just so busy trying to get the module to work myself sometimes I forget to be more specific in my post. Plus I thought it was more a problem with the page creating the image then the page displaying it if you catch my drift.
 
montego







PostPosted: Tue Jun 26, 2007 7:46 am Reply with quote

No problem. We deal with it all the time.
 
Display posts from previous:       
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> phpnuke 7.6

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©