Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

List all urls in a Dir

PDF files in a dir (should be simple)

     

trucqulent

8:24 pm on May 31, 2012 (gmt 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.

incrediBILL

11:41 pm on May 31, 2012 (gmt 0)

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



Try <?php instead of <php? and it will quit spitting code at you.

trucqulent

12:20 am on Jun 1, 2012 (gmt 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.

outrun

12:29 am on Jun 1, 2012 (gmt 0)

10+ Year Member



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.;
}
?>

trucqulent

12:37 am on Jun 1, 2012 (gmt 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.

rocknbil

4:47 pm on Jun 1, 2012 (gmt 0)

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



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.)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month