Jump to content

Passing Resource IDs using GET


tonyg

Recommended Posts

The code echo "IM is $im <br />"; returns "Resource id #2"

 

<a href='$_SERVER[php_SELF]?choice=drawLine&drawing=$im'>Draw Line</a><br /> shows up in the status bar as sending "drawing=Resource id #2".

 

But echo $_GET['drawing'] then shows "Resource id " instead of Resource id #2".

 

Can anyone tell me why?

Link to comment
https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/
Share on other sites

oh. So then you're probably assigning imagecreatefrompng or something to $im, which creates an image resource.  You would then normally do something with that resource and eventually use other functions to actually output an image to the browser or to a file or whatever.  So I guess you need to explain what it is you're trying to pass through the url and what it is you're trying to do overall, and show some code.

 

As far as your actual question earlier about the difference between resource id and resource id #2: there is none.  When you echo it, it shows the label for what $im is: a graphic resource, and it's id number.  But when you pass it through the url, #2 gets parsed.  That is,, through the url, # is looked at as an html anchor tag. 

The variable $im is set using:

 

$im = @imagecreatetruecolor($x, $y) or die("Cannot Initialize new GD image stream");

 

This displays a black rectangle x times y and

 

echo "IM on show is $im <br />";

 

returns:

 

IM on show is Resource id #2

 

Then it is passed as part of a URL:

     

<a href='$_SERVER[php_SELF]?choice=drawLine&drawing=$im'>Draw Line</a><br />

 

Then it is picked up as follows:

 

if(isset($_GET['drawing']))  {$im = $_GET['drawing'];  echo "Got existing drawing <br />";}

 

But:

 

echo "GET drawing is ".$_GET['drawing']."<br />";

 

displays "Resource id"

 

so other GD codes don't see $im and I get the message:

 

Warning: imageline(): supplied argument is not a valid Image resource in .../drawing.php on line 50

 

I am trying to build up an image by successive calls to various GD functions that add various components (lines, squares, text) to the image. It can be hard coded but I am testing to see if I can build up the image in pieces.

 

It will work if I can pass the image resource.

 

Hope this makes sense.

 

All resources used in a script are destroyed when execution on that page ends. An image resource won't exist outside the page it is on. If you are passing a resource id on the end of a URL, that resource id won't refer to the same instance of the image.

 

You will need to post your actual code showing what you are doing to get help with how to do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.