Welcome to WebmasterWorld Guest from 54.144.72.150

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

List all urls in a Dir

PDF files in a dir (should be simple)

     
8:24 pm on May 31, 2012 (gmt 0)

New User

joined:Apr 20, 2012
posts: 15
votes: 0


Hey guys,

I have a client that had me upload 384 flies to a dir. in wordpress.
What I need to do is simple, just add the URL's of those files as a link on one of his pages.

The problem is, when I post the code, it just spits the code back out on the page. it doesn't do anything at all.

Here's what Ive used


<php?
$directory = "wp-content/uploads/2012/05/";
$wp-content/uploads/2012/05/ = glob($directory . "*.pdf");
foreach($image as $image)
{
echo .$image.;
}
?>


for clarity, Ive posted the above code directly on the page in the HTML editor.

thanks in advance.
11:41 pm on May 31, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
posts:14624
votes: 88


Try <?php instead of <php? and it will quit spitting code at you.
12:20 am on June 1, 2012 (gmt 0)

New User

joined:Apr 20, 2012
posts: 15
votes: 0


<?php
$directory = "wp-content/uploads/2012/05/";
$wp-content/uploads/2012/05/ = glob($directory . "*.pdf");
foreach($image as $image)
{
echo .$image.;
}
?>


oops!

none the less, the page remains blank.
12:29 am on June 1, 2012 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 14, 2003
posts:438
votes: 0


You may have things a little Mixed up.

<?php
$directory = "wp-content/uploads/2012/05/";
$images= glob($directory . "*.pdf");
foreach($images as $image)
{
echo .$image.;
}
?>
12:37 am on June 1, 2012 (gmt 0)

New User

joined:Apr 20, 2012
posts: 15
votes: 0


that was the original code I used actually. it also results in a blank page.

Ive even tried testing with

if ($opendir = opendir ($dir)) {echo "victory"}


and no results.
4:47 pm on June 1, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


When you get blank pages, you need to check your error logs. Your last one has no closing semicolon so it will error. Or add, at the top of your scripts,

error_reporting(E_ALL);
ini_set('display_errors',1); // or true instead of 1

According to the manual [php.net] it doesn't look like you're using glob() correctly. Also note my addition in the path. Any file system operations are NOT URL's, they are system paths.

Same is true of $filesize - unless it's wherever PHP is executing (e.g., in the same directory) you need the full file system path.

Last, what's with the funny curly quotes?
echo .$image.;

I don't even know if those are valid. Do not edit PHP code in a rich text editor like MS Word. This will hose you up every time. If you don't have anything else, use Notepad (and then get something else.)


<?php
$directory = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/uploads/2012/05/";
// ALWAYS CHECK FIRST
if (is_dir($directory)) {
foreach (glob($directory.'*.pdf') as $pdf) {
echo "<p>$pdf size " . filesize("$directory/$pdf") . "</p>\n";
}
}
// THEN ERROR TRAP
else { echo "<p>Umm, $directory is not a directory.</p>"; }
?>


Trry that on for size. If you get "not a directory" try removing the trailing slash from the path:

$directory = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/uploads/2012/05"; // <-- that one

The only thing I'm not sure about is filesize - is the full path stored in $pdf already? (Don't think it is.)