php Related question.

Here non-phpBB topics can be discussed.
nads
New member
New member
Posts: 17
Joined: 15 Sep 2006, 16:27

php Related question.

Postby nads » 15 Sep 2006, 16:37

Hey guys... I have a query reagarding php. Im no genius when it comes to it you see.

Basically the problem is that on my forum I have an Images thread which I display all my images in from events I have attended. The problem is that there is a vast amount. So when I am posting I have to write my post like this...

Code: Select all

[img]http://www.mysite.com/images/image1.jpg[/img]
[img]http://www.mysite.com/images/image2.jpg[/img]
[img]http://www.mysite.com/images/image3.jpg[/img]
[img]http://www.mysite.com/images/image4.jpg[/img]
[img]http://www.mysite.com/images/image5.jpg[/img]


^^ now imagine that but with hundreds of images... not 5. As you can imagine it takes me a vast amount of time to write this out.

So basically what I am wondering... is if it is possible to write a php script which I can upload to the image directory in question... run it... and it outputs all of the image URL's in that directory wrapped in the phpBB IMG tag. From that I can copy and paste the output into my post instead of the slow painstaking process of writing out each individual image URL 1 by 1.

I hope what I am trying to achieve is clear enough for you wizards.

Thanks for reading and all help is appreciated :)
Image

nads
New member
New member
Posts: 17
Joined: 15 Sep 2006, 16:27

Postby nads » 15 Sep 2006, 18:18

Right guys... ive managed to get a working script....

[php]<?

//define the path as relative
$path = "/home/codanc/public_html/images/thedir";

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo "Directory Listing of $path<br/><br/>";

//running the while loop
while ($file = readdir($dir_handle))
{
echo "[img]http://www.yourweb.co.uk/images/thedir/";
echo "$file";
echo "[/img]<br/><br/>";
}

//closing the directory
closedir($dir_handle);

?> [/php]

Now this is really simple and everytime I upload a new folder full of images I have to login to my ftp and change the code around...

Would it be possible to make it so that when I run it... it shows a text box... then all i do is enter the path to the directory I want the output to be for??

Thanks again :)
Last edited by nads on 18 Sep 2006, 13:41, edited 1 time in total.
Image

User avatar
Noobarmy
Past Contributor
Past Contributor
Posts: 545
Joined: 02 Jun 2006, 11:19
Real name: Anthony Chu
Location: UK

Postby Noobarmy » 16 Sep 2006, 04:58

Try this:


FIND
$path = "/home/codanc/public_html/images/thedir";

REPLACE WITH
$path = $_GET['PATH'];

FIND
//using the opendir function

BEFORE, ADD
if ($path != '')
{

FIND
//closing the directory
closedir($dir_handle);

AFTER, ADD
}
else
{
$file = basename(__FILE__);
echo '<html><head></head><body><form action="' . $file . '" method="GET"><input type="text" value="" name="PATH" /></form></body></html>';
}

FIND
[img]http://www.yourweb.co.uk/images/thedir/

REPLACE WITH
$path

Image

User avatar
igorw
Past Contributor
Past Contributor
Posts: 1967
Joined: 01 Jun 2006, 20:48
Real name: Igor

Postby igorw » 16 Sep 2006, 11:30

Looks fine ;) FYI, you can also use [php] tags ;)

nads
New member
New member
Posts: 17
Joined: 15 Sep 2006, 16:27

Postby nads » 18 Sep 2006, 13:40

Im getting this error...

I have the list.php in my images directory... http://www.mysite.com/images/list.php

Code: Select all

Parse error: parse error, unexpected T_VARIABLE in /home/codanc/public_html/images/list.php on line 3


Im trying to resolve the problem but with no luck. any ideas?

This is exactly how my file looks...

[php]<?
FIND
$path = "/home/codanc/public_html/images";

REPLACE WITH
$path = $_GET['PATH'];

FIND
//using the opendir function

BEFORE, ADD
if ($path != '')
{

FIND
//closing the directory
closedir($dir_handle);

AFTER, ADD
}
else
{
$file = basename(__FILE__);
echo '<html><head></head><body><form action="' . $file . '" method="GET"><input type="text" value="" name="PATH" /></form></body></html>';
}

FIND
[img]http://www.tarncrew.co.uk/images/

REPLACE WITH
$path
?>[/php]


And thanks for your help :)
Image

User avatar
Noobarmy
Past Contributor
Past Contributor
Posts: 545
Joined: 02 Jun 2006, 11:19
Real name: Anthony Chu
Location: UK

Postby Noobarmy » 18 Sep 2006, 14:29

ok you were suppose to run those commands as you would for installing a mod.

So you FIND:$path = "/home/codanc/public_html/images"; replacing it with:$path = $_GET['PATH'];

ect...
Image

nads
New member
New member
Posts: 17
Joined: 15 Sep 2006, 16:27

Postby nads » 18 Sep 2006, 15:48

Feel free to call me retarded... but that post makes no sense to me.

What exactly are you saying I need to do. :)
Image

User avatar
Noobarmy
Past Contributor
Past Contributor
Posts: 545
Joined: 02 Jun 2006, 11:19
Real name: Anthony Chu
Location: UK

Postby Noobarmy » 18 Sep 2006, 16:51

Ok screw it i'll just tell you what to make it :P

Replace your file with the following:

[php]<?

//define the path as relative
$path = $_GET['PATH'];

//using the opendir function
if ($path != '')
{
$dir_handle = @opendir($path) or die("Unable to open $path");

echo "Directory Listing of $path<br/><br/>";

//running the while loop
while ($file = readdir($dir_handle))
{
echo "[img]" . $path;
echo "$file";
echo "[/img]<br/><br/>";
}

//closing the directory
closedir($dir_handle);
}
else
{
$file = basename(__FILE__);
echo '<html><head></head><body><form action="' . $file . '" method="GET"><input type="text" value="" name="PATH" /></form></body></html>';
}

?>[/php]
Image

nads
New member
New member
Posts: 17
Joined: 15 Sep 2006, 16:27

Postby nads » 19 Sep 2006, 23:42

you, sir .... are awesome!!

thanks very much.
Image


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests