homepage Welcome to WebmasterWorld Guest from 54.197.110.151
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
List all urls in a Dir
PDF files in a dir (should be simple)
trucqulent



 
Msg#: 4460101 posted 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

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



 
Msg#: 4460101 posted 11:41 pm on May 31, 2012 (gmt 0)

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

trucqulent



 
Msg#: 4460101 posted 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

10+ Year Member



 
Msg#: 4460101 posted 12:29 am on Jun 1, 2012 (gmt 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.;
}
?>

trucqulent



 
Msg#: 4460101 posted 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

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



 
Msg#: 4460101 posted 4:47 pm on Jun 1, 2012 (gmt 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.)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved