Passing one php function result as a parameter to another php function
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Passing one php function result as a parameter to another php function
I store images on my website as mysql blobs. I'd like to retrieve an image via an existing php function, and resize them via another function, both on the fly.
To retrieve the image, I use;
<img src="retrieve_image.php?itemId=1">
To resize a stored jpg, I can use:
<img src="resize_image.php?image=image.jpg">
How can I combine the two? I would like to have something like:
<img src="resize_image.php?image=retrieve_image.php?itemId=1">
Here's the resize_image.php file I'm using - it's almost verbatum from the (wonderful) PHP and MySql programming book, which I think is a New Riders offering (it's at work or I would confirm)...
I presume the bit you're most interested in is the final stanza...
<?php
$image = $HTTP_GET_VARS['image'];
//set dimensions desired for webpage viewing
if (!$max_width)
$max_width = 200;
if (!$max_height)
$max_height = 150;
Well, now I know where the 'image' variable go but not for the 'itemId', I need this information to help you to combine them and make the url from that.
Tried that (tried all variations again this morning just to be sure!).
I think the problem may lie around the ImageCreateFromJpeg function - does anyone know if ImageCreateFromString will directly decypher a blob image? It's a bit heavy thinking for my wee mind this early on a Sunday morning...!
You can try combine retrieve_image.php and resize_image.php in one script file, and modify it so when it get 'itemId' from database, if it knows it is an image, then it resize it.
With one script for all, you just indicate 'itemId' in the url
Just what I've been doing; it doesn't work yet, but I'll keep at it. (error - The image “http://qwerty/full_resize.php?itemId=1” cannot be displayed, because it contains errors. - meaningful!)
<?php
global $itemId;
if(!is_numeric($itemId)) die("Invalid itemId specified");
#My connection details for my mySql db
include 'details.php';
$sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
$dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase");
Here's the (almost) complete script - I've cheated slightly, by calling my original retrieve script (download_stockblob.php) purely to get it's size. It works, though! The main thing is, I can now create thumbnails, etc, on the fly...
<?php
global $itemId;
if(!is_numeric($itemId)) die("Invalid itemId specified");
include 'details.php';
$sConn = mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server");
$dConn = mysql_select_db($dbDatabase, $sConn) or die("Couldn't connect to database $dbDatabase");
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.