View Full Version : a good challenge for u php freaks, I mean masta's
Weapon
January 22nd, 2002, 06:52
convert this cgi image script to php
#!/usr/local/bin/perl
$headfile = ' ';
$footfile = ' ';
$File = $ENV{'QUERY_STRING'};
unless (open (DATA,"$headfile")) {die (&error);}
if ($uselock eq '1') {
flock DATA, 2;
seek DATA, 0, 0;
}
@headinfo = <DATA>;
if ($uselock eq '1') {
flock DATA, 8;
}
close (DATA);
foreach $headline (@headinfo){
$heading = $heading.$headline;
}
unless (open (DATA,"$footfile")) {die (&error);}
if ($uselock eq '1') {
flock DATA, 2;
seek DATA, 0, 0;
}
@footinfo = <DATA>;
if ($uselock eq '1') {
flock DATA, 8;
}
close (DATA);
foreach $footline (@footinfo){
$footer = $footer.$footline;
}
print "Content-type:text/html\n\n";
print "$heading";
print "<CENTER><IMG SRC=\"$File\"></CENTER>";
print "$footer";
:bandit2:
megapuzik
January 22nd, 2002, 10:23
Hey...
I know php, but dont know perl.....what this script does ?
Weapon
January 22nd, 2002, 20:08
its an image posting script, where instead of making a html page for each image it grabs a header and then a footer file
niv
January 22nd, 2002, 20:18
That is utterly complicated for a script that only does that.
If you know what you're doing, this is good enough:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$headfile = ' '; # insert filename
$footfile = ' '; # insert filename
$File = $ENV{'QUERY_STRING'};
if (-e $headfile && -e $footfile){
open (HEADER, $headfile);
open (FOOTER, $footfile);
print <HEADER>;
close (HEADER);
print "<img src=\"$File\">";
print <FOOTER>;
close (FOOTER);
} else {
print "Error.\n";
}
PHP Version:
<?
$headfile='';
$footfile='';
include ("$headfile");
echo ("<img src\"$QUERY_STRING\">");
include ("$footfile");
?>
Weapon
January 22nd, 2002, 20:23
and how would I call the image with the php version?
niv
January 22nd, 2002, 20:25
blahblah.php?blahblahblah [in relation to location of blahblah.php]
i.e.
http://www.myacen.com/otashki/blahblah.php?weeps_cant_spell.gif
would go to http://www.myacen.com/otashki/weeps_cant_spell.gif
Seriously, you can't spell [if japanese was your goal], there is no sh character in either the hiragana or katakana character sets.
Weapon
January 22nd, 2002, 21:01
huh what do u mean I can't spell? :eek: not my fault the keys are missing :biggrin2:
niv
January 22nd, 2002, 21:05
Weepsie-poopoo, I'm saying there's no sh, but there's shi. :classic2:
Weapon
January 22nd, 2002, 21:24
grrrrrr weepsie pooo grrr :angry2: gonna kill meow grrrr :angry2:
Weapon
January 23rd, 2002, 01:57
errr don't think it works, see http://www.aznpride.com.kg/
megapuzik
January 23rd, 2002, 03:12
Hey hayama, there is now QUERY_STRING func. in php...
maybe you can try this :
<?
$headfile='';
$footfile='';
include ("$headfile");
print '<img src='.$img.'>';
include ("$footfile");
?>
and to display some image, you need to do this...
bla.php?img=image.gif
niv
January 23rd, 2002, 09:01
I was using the original script, so I used $QUERY_STRING (as in $ENV{'QUERY_STRING'}) in Perl.
Dusty
January 23rd, 2002, 19:44
there is [no] QUERY_STRING func. in phpYes there is.
Woofcat
January 23rd, 2002, 20:16
well of course there is no query string "function," and if your php config is fully optimized like mine there is no $QUERY_STRING variable either... best to use getenv()... and readfile() is more efficient than include() (and closer to what the original perl script does)...
<?readfile('')?><img src="<?=getenv('QUERY_STRING')?>"><?readfile('')?>
megapuzik
January 24th, 2002, 01:34
wierd, I run a loop with all the GLOBAL vars, there is no quary string there...
Weapon
February 12th, 2002, 03:40
sorry for bringing an old thread up, but how do I specify a image size for the image? ( eg, width=, height= )
megapuzik
February 12th, 2002, 03:58
add these var to your page :
$height = "50";
$width = "10";
and add theme !
<?readfile('')?><img src="<?=getenv('QUERY_STRING')?>" width="<?=width?>" height="<?=height?>"><?readfile('')?>
thats all
Weapon
February 12th, 2002, 21:27
huh :confused2
megapuzik
February 13th, 2002, 04:50
Its like html, just with php variables
Weapon
February 13th, 2002, 05:36
:confused2 where exactly do I put those things? top of page? bottom? above body tag? what?
gyrbo
February 13th, 2002, 06:04
Replace the image stuff with this:
<img src="<?=echo $src;?>" width="<? echo $width;?>" height="<? echo $height;?>">
And then you can call the image like: script.php?src=image.gif&height=50&width=100
You can also use an image lib, but that would slow down and would require me to search into documentation:D , besides it's possible you don't have the lib installed.
Weapon
February 13th, 2002, 06:29
nope. :confused2 check it for urself at http://gameswd.host.sk/image.php?img=wallpaper/acec3800003.jpg&height=500&width=700 click on image number 3's 800x600
also this is what I did, is it right? :confused2
before:
<?
$headfile='/mnt/host-users/gameswd/head.txt';
$footfile='/mnt/host-users/gameswd/foot.txt';
include ("$headfile");
print '<img src="">';
include ("$footfile");
?>
after:
<?
$headfile='/mnt/host-users/gameswd/head.txt';
$footfile='/mnt/host-users/gameswd/foot.txt';
include ("$headfile");
print '<img src="<?=echo $src;?>" width="<? echo $width;?>" height="<? echo $height;?>">';
include ("$footfile");
?>
:chinese2:
megapuzik
February 13th, 2002, 07:00
print '<img src="<?=$src;?>" width="<?=$width;?>" height="<?=$height;?>">';
try now
go to like this : bla.php?src=bla.gif&width=120&height=121
Weapon
February 13th, 2002, 14:25
nope :(
http://gameswd.host.sk/image.php?src=wallpaper/acec3800003.jpg&width=700&height=500
megapuzik
February 13th, 2002, 14:42
Just tested this :
<?
print "<html><head><title>image showing template</title></head><body>";
if(empty($src))
{
print "No picture selected\n<br>";
}
else{print "<img src=\"$src\" height=\"$height\" width=\"$width\">"; }
print "</body></html> ";
?>
Work fine to me.
Weapon
February 13th, 2002, 18:10
hmmmm the original script was that it was suppose to call a header and footer file for use as templates as well :p
megapuzik
February 13th, 2002, 18:12
Originally posted by Weapon
hmmmm the original script was that it was suppose to call a header and footer file for use as templates as well :p
so ?? try to put the header and the footer by yourself, if you do not succed, I will rewrite it for you :)
Weapon
February 13th, 2002, 18:23
Would it br this then?
<?
$headfile='/mnt/host-users/gameswd/head.txt';
$footfile='/mnt/host-users/gameswd/foot.txt';
if(empty($src))
{
print "No picture selected\n<br>";
}
include ("$headfile");
else{print "<img src=\"$src\" height=\"$height\"
include ("$footfile");
width=\"$width\">"; }
?>
:chinese2:
megapuzik
February 13th, 2002, 18:33
this :
<?php
$headfile='/mnt/host-users/gameswd/head.txt';
$footfile='/mnt/host-users/gameswd/foot.txt';
print "<html><head><title>image showing template</title></head><body>";
if(empty($src))
{
print "No picture selected\n<br>";
}
else {
include ("$headfile");
"<img src=\"$src\" height=\"$height\" width=\"$width\">";
include ("$footfile");
}
print "</body></html>";
?>
{copy N past :p}
that will show you the msg "no picture selected" if you run it without putting some value in src (bla.php?src).
Anyway, learn here (http://www.daholygoat.com) some basic PHP, its very good and really fun.
:)
Weapon
February 13th, 2002, 19:38
thx :p , I was thinking about learning php too
Weapon
February 13th, 2002, 19:49
y doesn't it work for me? :mad:
http://gameswd.host.sk/image.php?src=wallpaper/acec3800003.jpg&width=700&height=500
megapuzik
February 14th, 2002, 06:29
Originally posted by Weapon
y doesn't it work for me? :mad:
http://gameswd.host.sk/image.php?src=wallpaper/acec3800003.jpg&width=700&height=500
Are you sure ?? it is working fine.
Weapon
February 14th, 2002, 14:13
yup :D thats because I used my php skillz and fixed it :biggrin2:
megapuzik
February 14th, 2002, 15:19
"fixed" ?? I tested the script the I gave you, its your problems that the script didnt work :angry2:
Weapon
February 14th, 2002, 21:24
what I did was this:
<?php
$headfile='/mnt/host-users/gameswd/head.txt';
$footfile='/mnt/host-users/gameswd/foot.txt';
print "<html><head><title>image showing template</title></head><body>";
if(empty($src))
{
print "No picture selected\n<br>";
}
else {
include ("$headfile");
print "<img src=\"$src\" height=\"$height\" width=\"$width\">";
include ("$footfile");
}
print "</body></html>";
?>
and it worked :)
megapuzik
February 15th, 2002, 04:52
Originally posted by Weapon
what I did was this:
<?php
$headfile='/mnt/host-users/gameswd/head.txt';
$footfile='/mnt/host-users/gameswd/foot.txt';
print "<html><head><title>image showing template</title></head><body>";
if(empty($src))
{
print "No picture selected\n<br>";
}
else {
include ("$headfile");
print "<img src=\"$src\" height=\"$height\" width=\"$width\">";
include ("$footfile");
}
print "</body></html>";
?>
and it worked :)
WOOOOPS, forgot to "print" it :o sorry :biggrin2:
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.