 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
06-03-2008, 01:21 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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"))
{
|
|
|
|
06-03-2008, 03:29 PM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
06-03-2008, 04:16 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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.
|
|
|
|
06-03-2008, 05:44 PM
|
#4 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
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; ...
|
|
|
|
06-03-2008, 05:56 PM
|
#5 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
|
The Following 2 Users Say Thank You to delayedinsanity For This Useful Post:
|
|
06-03-2008, 06:00 PM
|
#6 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
Didn't know that  after all those years with casual programming 
|
|
|
|
06-03-2008, 06:58 PM
|
#7 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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.
|
|
|
|
06-03-2008, 07:34 PM
|
#8 (permalink)
|
|
The Contributor
Join Date: May 2008
Location: Denmark
Posts: 70
Thanks: 3
|
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:
<?php if (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 :)
|
|
|
|
|
The Following User Says Thank You to SpYkE112 For This Useful Post:
|
|
06-03-2008, 07:38 PM
|
#9 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
Ok. I'll dive into it here shortly. I have to fix this darn error first.
|
|
|
|
06-04-2008, 12:24 AM
|
#10 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
06-04-2008, 01:51 PM
|
#11 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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.
|
|
|
|
06-04-2008, 04:39 PM
|
#12 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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
|
|
|
|
|
06-04-2008, 04:52 PM
|
#13 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
06-04-2008, 05:01 PM
|
#14 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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?
|
|
|
|
06-04-2008, 05:38 PM
|
#15 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
06-04-2008, 05:46 PM
|
#16 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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.
|
|
|
|
06-04-2008, 05:51 PM
|
#17 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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.
|
|
|
|
06-04-2008, 05:51 PM
|
#18 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
06-04-2008, 05:56 PM
|
#19 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
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
|
|
|
|
06-04-2008, 06:09 PM
|
#20 (permalink)
|
|
The Contributor
Join Date: May 2008
Posts: 30
Thanks: 5
|
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??
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|