• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Image on a fly

Originally posted by Johnny
perl is fine. but where do I put in my html design there? I don't see any where to put it.

Just edit the header and footer, then you can put your design.
 
whoops, hey sorry i didnt read the post, i assumed that you wanted what i said...


also yupapa, ever heard of editing your posts? posting many times in a row is annoying
 
Code:
#!/usr/bin/perl
use CGI qw(:standard);

my $imageDIR = qq($ENV{'DOCUMENT_ROOT'}/path/to/image/dir);
my $imageURL = qq([url]http://www.yourdomain.com/path/to/image/dir[/url]);
my @image_ext = ("jpg","jpeg","jpe","gif");
my $called_image = param('image');

print "Content-Type: text/html\n\n";

&header;
chdir($imageDIR);
if(-f $called_image) {
	print qq(
		<IMG SRC="$imageURL/$called_image">
	);
} else {
	print "Could not find your image";
}
&footer;


sub header {
	print qq(
	<HTML>
	<HEAD><TITLE>My images</TITLE></HEAD>
	<BODY>
	Header<P>
	);
}

sub footer {
	print qq(
	<P>Footer<P>
	</BODY>
	</HTML>
	);
}

__END__

call your image like this:
http://www.yourdomain.com/cgi-bin/thescript.pl?image=file.jpg
 
so u telling me.. if I want to mine look like "http://www.amazinghumor.com/p.shtml?0261.jpg "

Then I have to do alot of hard work with that header and footer?
 
Originally posted by Johnny
so u telling me.. if I want to mine look like "http://www.amazinghumor.com/p.shtml?0261.jpg "

Then I have to do alot of hard work with that header and footer?

Of course, what you now have to do is to edit the header and footer in my script:

edit between print qq( and );
Code:
sub header {
	print qq(
	<HTML>
	<HEAD><TITLE>My images</TITLE></HEAD>
	<BODY>
	Header<P>
	);
}

sub footer {
	print qq(
	<P>Footer<P>
	</BODY>
	</HTML>
	);
}

Then whenever you call the image using the script, it will show the header and footer.
 
Also remove line 5, because it is useless:
my @image_ext = ("jpg","jpeg","jpe","gif");

And show me the result when your thing is done
Anything else you want?? Track how many downloads of your images? I can do that in 5 mins.
 
Originally posted by is0lized
just make a normal layout, and where you would normaly put the content, put the image


Huh? I wish it was that easy. I have to find a way to sperate the thing into 2 section so that it would look like my main page...


And YUPAPA ,
Yes please do that download tracker..
I wounder if you could also do that voting thing.. like let people rate the pictures?
 
if this is your layout

Code:
<html>
<head>
    <title>
        Title
    </title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
CONTENT HERE
</center>
</body>
</html>

then put this in header

Code:
<html>
<head>
    <title>
        Title
    </title>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>


and this in footer

Code:
</center>
</body>
</html>



not very hard
 
OK,

1. you want the downloads of the pic to be shown below the image?
2. you want to get the downloads of a pic by entering a URL:
&nbsp; something like: yourdomain.com/script.pl?action=show_download&file=yourfile.jpg

1 or 2?
 
what not 1 file, shows how many clicks for all forums


like log.html

blah.jpg - 7 clicks
sdjds.gif - 2 clicks



ect
 
well I dont' knwo what you talking about.. but I want it to show how many time the pic has been viewed..
 
Originally posted by Johnny
how do i edit it so that I would have my own html design? cause this is just a plain page with the image you call out.
just change the header/footer html around the php code [the code inside the <? ?> tags] to your liking. i just used the bare-bones html layout for the example.

or, like someone else had posted:
PHP:
<?

include("/path/to/header.php");

if (file_exists("$DOCUMENT_ROOT/images/$QUERY_STRING")) {
?>
<img src="/images/<? echo("$QUERY_STRING"); ?>" border="2"><br>
<?
}

else {
?>
<b>No such image.</b><br>
<?
}

include("/path/to/footer.php");

?>

Originally posted by Johnny
And on that site they had "http://www.weezerfans.com/rock/discs/sayitaintso.jpg"
that is where the image is at.. but the script "http://www.weezerfans.com/images/discs.php" is here.. aren't they suppose to be in teh same dir?
nope, the images directory is embedded in the php code... you can put the php file anywhere you want.
 
Last edited:
Originally posted by keith
just change the header/footer html around the php code [the code inside the <? ?> tags] to your liking. i just used the bare-bones html layout for the example.

or, like someone else had posted:
PHP:
<?

include("path/to/header.php");

if (file_exists("$DOCUMENT_ROOT/images/$QUERY_STRING")) {
?>
<img src="/images/<? echo("$QUERY_STRING"); ?>" border="2"><br>
<?
}

else {
?>
<b>No such image.</b><br>
<?
}

include("path/to/footer.php");

?>

nope, the images directory is embedded in the php code... you can put the php file anywhere you want.


don't you mean outside the <? ?>

like
<html>
<head>
<title>Images Viewer</title>
</head>

<body>

<center>
<table border =1 color=pink>
blahbalh

<?
if (file_exists("$DOCUMENT_ROOT/images/$QUERY_STRING")) {
?>
<img src="/images/<? echo("$QUERY_STRING"); ?>" border="2"><br>
<?
}

else {
?>
<font face="arial" size="2"><b>
Whoops! No such image.<br>
</b></font>
<?
}
?>

blah blah blah </table>
</center>

</body>
</html>
 
when i said 'inside', i was referring to the php code... yeah, the html code is outside those tags... you've got the right idea.
 
O i see thanks..

Is there anything i need to a php before I upload .. like cgi i need to chmod it and stuff. cause I don't know anytime about php .. is there any site that i would learn the basic of it?

BTW do you know if i could do text on a fly? like u articles on msnbc.com or is there a php script out ther would do that the content manigament stuff? I am willing to pay big bucks for it.
 
There:

Code:
#!/usr/bin/perl
use CGI qw(:standard);

my $imageDIR = qq($ENV{'DOCUMENT_ROOT'}/path/to/image/dir);
my $imageURL = qq([url]http://www.yourdomain.com/path/to/image/dir[/url]);
my $trackerDB = qq(tracker.db);
my $called_image = param('image');
my $action = param('action');


print "Content-Type: text/html\n\n";

&header;

if($action eq "show_image") { &show_image; }
elsif($action eq "show_downloads") { &show_downloads; }
else { print "What are you doing?"; }

sub show_image {
	if(-f "$imageDIR/$called_image") {
		&add_downloads;
		print qq(
			<IMG SRC="$imageURL/$called_image">
		);
	} else {
		print "Could not find your image $called_image";
	}
}

sub add_downloads {
	open(TRACKER,"$trackerDB");
	while(<TRACKER>) {
		chomp;
		($filename,$downloads) = split(/\|/,$_);
		if($filename eq $called_image) {
			$newdownloads = $downloads + 1;
			$write .= "$filename|$newdownloads\n";
			$found = 1; 				 #If the record is found in the database, set to one
		} else {
			$write .= "$_\n";
		}
	}
	close(TRACKER);
	$newrecord = "$called_image|0";
	open(TRACKER,">$trackerDB");
		print TRACKER $write;
		if(!$found) {
			print TRACKER "$newrecord\n"; #If the record could not be found in the database, add a new record
		}
	close(TRACKER);
}

sub show_downloads {
	open(TRACKER,"$trackerDB");
	@record = <TRACKER>;
	close(TRACKER);
	foreach (@record) {
		chomp;
		($filename,$downloads) = split(/\|/,$_);
		print qq($filename has been downloaded $downloads times<BR>);
	}
}

sub header {
	print qq(
	<HTML>
	<HEAD><TITLE>My images</TITLE></HEAD>
	<BODY>
	Header<P>
	);
}

sub footer {
	print qq(
	<P>Footer<P>
	</BODY>
	</HTML>
	);
}

&footer;

__END__

TO show the number of downloads of each file go here
yourdomain.com/script.pl?action=show_downloads

TO view pictures, go here
yourdomain.com/script.pl?action=show_image&image=xxxxx.jpg
It will automatically save the number of downloads whenever someone view the picture

IMPORTANT: Make sure the database which is used to store the number of downloads is writable. CHMOD 0666.

That's about it... I guess
 
Last edited:
Back
Top