Jump to content

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

It's because you queried your database and the results were returned to $im.  $im is the result source for your query.  You have to actually pull the data out of the result source, using one of several functions, such as mysql_fetch_array.

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.

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.