TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Calling an image (http://www.talkphp.com/absolute-beginners/2886-calling-image.html)

 j4v1 06-03-2008 01:21 PM

Calling an image

A few quick questions that would truly help me complete a project i'm working on.

I have the following script that generates an image. The script works great, but heres where I'm stuck:

I need to call the image it generates from an HTML file. So, in that file I'm unsure on how to tell the script to execute and then go out and grab the generated image.

PHP Code:

 <?php resize("./", "http://images.wsdot.wa.gov/nwflow/flowmaps/sysvert.gif", "538", "./"); function resize($cur_dir,$cur_file, $newwidth,$output_dir) {     $dir_name =$cur_dir;     $olddir = getcwd();$dir = opendir($dir_name);$filename = $cur_file;$format='image/gif';     if(preg_match("/.jpg/i", "$filename")) {$format = 'image/jpeg';     }     if (preg_match("/.gif/i", "$filename")) {$format = 'image/gif';     }     if(preg_match("/.png/i", "$filename")) {   Wildhoney 06-03-2008 03:29 PM What I would do is add the following code: html4strict Code: <img src="resizeImage.php" /> Obviously you don't want to resize every time, so check the size of the image and then decide whether to refresh or not. Embed the actual image in the PHP file once done, and set the content-type.  j4v1 06-03-2008 04:16 PM Actually, I need the gif to resize everytime. So, I'll need the script to execute first and then call the image to display on screen.  SpYkE112 06-03-2008 05:44 PM why do you use the function before it is declared? And if that is a complete copy / paste then you need a closing bracket "}" for the function.. But as Wildhoney says, that is the way i would prefer it to be done, but be aware that is you use some sort of external input in the script, like a$_GET or $_POST, it could evolve into some sort of security breach, but as it is now it is okay :) And by the way, you don't have to declare variables twice? I refer to these: PHP Code:  ...$dir_name = $cur_dir;...$filename = $cur_file; ...   delayedinsanity 06-03-2008 05:56 PM Quote:  why do you use the function before it is declared? PHP is compiled server side before it's ran, you can declare a function anywhere on the page, and use it anywhere else as you please. Same with classes, etc. You can even use a function inside of itself (recursive functions). It is PHP Hypertext Preprocessor after all. ;-) -m  SpYkE112 06-03-2008 06:00 PM Didn't know that :-$ after all those years with casual programming :-!

 j4v1 06-03-2008 06:58 PM

Well, I'm stuck at the moment. I keep getting an
Quote:
 http 500 error The requested operation requires elevation
everytime I try to preview the page.

I'm confused abit on GET & POST. Is that something I call on the html file? this particular page is only going to open locally, so I'm not too overly concerned about security. I'd just like it to work.

 SpYkE112 06-03-2008 07:34 PM

GET and POST are different methods of sending user input to the server, GET is values in the url like:
Code:

http://example.com/?get=this
You can call it whatever you want it is very easy to manipulate.

POST on the other is a bit more complicated but indeed possible to manipulate, but if you know some basic PHP you will be able to secure your self. But POST is the most popular way of sending form data into a PHP script.

A simple code snippet with POST...
PHP Code:

 <?phpif (isset(\$_POST['submit'])) {    echo('You submitted');}?><form action="" method="post">    <input type="submit" name="submit" value="submit" /></form> 
That is the basic things about GET and POST :)

 j4v1 06-03-2008 07:38 PM

Ok. I'll dive into it here shortly. I have to fix this darn error first.

 delayedinsanity 06-04-2008 12:24 AM

You're running your server on Windows Vista arencha? Don't worry, that error doesn't mean you need to put your computer up on cinder blocks or on the second floor, as some may suspect. Chances are if you're running Vista, you just need to turn off the damned UAC, which should never have been turned on in the first place... didja know somebody at MS actually admitted they added that to Vista to annoy the shit out of people? Because apparently if you annoy the crap outta people, they don't try and mess with sensitive system settings.... OR... they buy a Mac. Dumba**es.

Anywho. You can turn UAC off by running msconfig, hopping over to the tools tab, and selecting the Disable UAC option. It'll make your life much happier all in all even if this isn't your problem.
-m

 j4v1 06-04-2008 01:51 PM

Ok. Somehow. After changing all the exe to "Run as Administrator" (go figure this was MS's doing) I don't get an error. I've also disabled UAC for good measure.

Now my problem is that every time I hit preview my script from the editor it only display the script on the browser and does not run the script.

 j4v1 06-04-2008 04:39 PM

Ok. I'm back in business. Thank you everyone. Now to get back to making this script work. The funny thing is that this script was working fine. Now sure what I've done in the past few days...I know i've been playing around w/ all the various apache and php files.

I'm now getting the following error:
Quote:
 PHP Fatal error: Call to undefined function imagecreatefromgif() in C:\My Web Sites\mysite\test.php on line 32

 delayedinsanity 06-04-2008 04:52 PM

Sounds like when you reinstalled, PHP wasn't compiled with GD support. You can check phpinfo() to see if it lists the GD module, function_exists('gd_info') or open your PHP.ini and search for the following:

 [PHP_GD2] extension=php_gd2.dll 

If you don't see that, then you don't have GD, which means you don't have imagecreatefromgif()
-m

 j4v1 06-04-2008 05:01 PM

how do I check phpinfo()? Also, I've check the php.ini and i've check the apache\bin\php.ini and both have the "extension=php_gd2.dll". Is there a way to see if the gd2.dll is the correct one?

 delayedinsanity 06-04-2008 05:38 PM

PHP Code:

 <?php phpinfo() ?> 
Put that in a file and open it in your browser. Check the first table that comes up for "Configure Command" and see if it says --with-gd anywhere in that string (most likely --with-gd=shared). You can also scroll down and look for the 'gd' configuration table (should be after ftp and before hash), and check that all the options are enabled and not disabled for some reason.
-m

edit: To make sure the dll is there, it should be in your path\to\PHP\ext\ folder, named php_gd2.dll

 j4v1 06-04-2008 05:46 PM

Now something i did notice is that the php.ini didn't have a section [PHP_GD2] like you had above, it just listed the dll along w/ the other extensions.

 j4v1 06-04-2008 05:51 PM

YOU ROCK!!! I've never noticed this. Its actually pretty cool. I'm seeing that the php info is going off an old php install that I had, before xampp. How can I go and switch that up...or should I? The reason why I went w/ xampp is because it had phpcgi.exe, where the install of Php that I had original didn't have that.

 delayedinsanity 06-04-2008 05:51 PM

Honestly I don't have the foggiest if it makes a difference or not. My php.ini looks like this as far as to how it lists modules;

 [PHP_EXIF] extension=php_exif.dll [PHP_GD2] extension=php_gd2.dll [PHP_MBSTRING] extension=php_mbstring.dll [PHP_MYSQL] extension=php_mysql.dll [PHP_MYSQLI] extension=php_mysqli.dll [PHP_SMTP] extension=php_smtp.dll 

So I would assume so, but I don't like assuming. Sounds like with all the troubles your having though it may be an idea in the future to try a different WAMP or give a go at installing by hand (my preferred method).
-m

 delayedinsanity 06-04-2008 05:56 PM

Quote:
 The reason why I went w/ xampp is because it had phpcgi.exe, where the install of Php that I had original didn't have that.
Any particular reason? PHP installed as a module is actually much faster, and also permits a few odds and ends here and there that may be useful in the future, which PHP installed as CGI doesn't. As for using different php.ini files, that is determined in your httpd.conf for apache with the following line:

 PHPIniDir "C:/path/to/folder/containing/proper/ini/usually/path/to/PHP/" 

Hope this helps.
-m

 j4v1 06-04-2008 06:09 PM

M
You are a Godsend! I'm back in business!

Now, I'm back trying to figure out how to have an html file, force my script above to display the image.

I've tried <img src=test.php/>, but all I get is a box w/ an x in it. I have to some how tell the script to echo the image directly instead of saving it as a file...maybe??

All times are GMT. The time now is 04:52 PM.