homepage Welcome to WebmasterWorld Guest from 184.73.52.98
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
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:4460103
 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




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

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

trucqulent




msg:4460190
 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




msg:4460193
 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:4460195
 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




msg:4460430
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved