开发者

php - get full image path from server

how can i get image path on server using "browse" button in a html form, select the file (double clicking the file returning its full path), and put the result image path into variable $img_path?

let's say the image dir in my server is /images, i'd like to get path of "foo.jpg", the full image path should be "/images/foo.jpg"

so, all i have to do is : 1. create form which contain "browse" button or something like that - that allow me to explore "images" directory at my server 2. exploring "images" dir, all files listed and clickable, locate "foo.jpg", select it, and voila, i get the image path "/images/foo.jpg"

any lil' help would be appreciated.. Thanks


@CodeCaster thanks for your respond.. but this is all i want (at least closer) :

<?php

$dir = '/images';
if (!isset($_POST['submit'])) {
    if ($dp = opendir($dir)) {
        $files = array(开发者_高级运维);
        while (($file = readdir($dp)) !== false) {
            if (!is_dir($dir . $file)) {
                $files[] = $file;
            }
        }
        closedir($dp);
    } else {
        exit('Directory not opened.');
    }
    if ($files) {
        echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
        foreach ($files as $file) {
            echo '<input type="checkbox" name="files[]" value="' . $file . '" /> ' .
                 $file . '<br />';
        }
        echo '<input type="submit" name="submit" value="submit" />' .
             '</form>';
    } else {
        exit('No files found.');
    }
} else {
    if (isset($_POST['files'])) {
        foreach ($_POST['files'] as $value) {
            echo $dir . $value . '<br />';
        }
    } else {
        exit('No files selected');
    }
}

?>


using "dir" you can achieve your goal.

<?php
 $d = dir("/etc/php5");
 echo "Handle: " . $d->handle . "\n";
 echo "Path: " . $d->path . "\n";
 while (false !== ($entry = $d->read())) {
   echo $entry."\n";
 }
 $d->close();
?>


You could use dir:

echo "<ul>";

$d = dir("images");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo "<li><a href=\"/images/" . $entry . "\">" . $entry . "</a></li>";
}
$d->close();

echo "</ul>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜