tonyg Posted October 23, 2008 Share Posted October 23, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/ Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672687 Share on other sites More sharing options...
tonyg Posted October 23, 2008 Author Share Posted October 23, 2008 I should have made it clear that I am using the GD library. I am not accessing a mysql database. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672693 Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672697 Share on other sites More sharing options...
tonyg Posted October 23, 2008 Author Share Posted October 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672710 Share on other sites More sharing options...
DarkWater Posted October 23, 2008 Share Posted October 23, 2008 You cannot pass it in the URL. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672711 Share on other sites More sharing options...
tonyg Posted October 23, 2008 Author Share Posted October 23, 2008 Ok. So can it be done some other way? Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672724 Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 Pass it as a session variable. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672732 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2008 Share Posted October 23, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-672741 Share on other sites More sharing options...
tonyg Posted October 23, 2008 Author Share Posted October 23, 2008 Code attached as requested [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/129747-passing-resource-ids-using-get/#findComment-673093 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.