マシューホール:
私が使用しようとしている現時点では、ユーザは、選択した画像が表示されている名前のいずれかを選択したら、私は特定のフォルダ内の画像ファイルの名前で埋めドロップダウンメニューを持っているPHPコードを持って、私が欲しいのですボタンを提出。私はjqueryのか、他の言語を使用しないようにしようとしています
<?php
$folder = 'C:\Users\source\\';
echo '<form action="" method="post">'."\n".'<select name="image">'."\n".
dropdown(image_filenames($folder), @$_POST['image']).
'</select>'."\n".'<input type="submit" name="submit">'."\n".'
</form>';
function image_filenames($dir)
{
$handle = @opendir($dir)
or die("I cannot open the directory '<b>$dir</b>' for reading.");
$images = array();
while (false !== ($file = readdir($handle)))
{
if (preg_match('/^.*\.(jpg|jpeg|png|gif|svg)$/', $file))
{
$images[] = $file;
}
}
closedir($handle);
return $images;
}
function dropdown($options_array, $selected = null)
{
$return = null;
foreach($options_array as $option)
{
$return .= '<option value="'.$option.'"'.
(($option == $selected) ? ' selected="selected"' : null ).
'>'.$option.'</option>'."\n";
}
return $return;
}
if (isset($_POST['submit'])) {
echo '<img src=C:\Users\source'. $row['images'] . ' />';
}
?>
アントニー・ジャック:
あなたは、プロジェクト内のファイルを維持する必要がある必要があります...
変化する
$folder = 'C:\Users\source\\';
に
$folder = 'images\\';
画像をプロジェクト内のフォルダ名です...
XAMPPまたはwamppは、ローカルパスファイルを考慮していません...
そして、それはうまくとして画像を表示しません...
これは参考ホープ...
私が変更されている二つの場所をあなたのコードに...
<?php
$folder = 'images\\'; // changed here
echo '<form action="" method="post">'."\n".'<select name="image">'."\n".
dropdown(image_filenames($folder), @$_POST['image']).
'</select>'."\n".'<input type="submit" name="submit">'."\n".'
</form>';
function image_filenames($dir)
{
$handle = @opendir($dir)
or die("I cannot open the directory '<b>$dir</b>' for reading.");
$images = array();
while (false !== ($file = readdir($handle)))
{
if (preg_match('/^.*\.(jpg|jpeg|png|gif|svg)$/', $file))
{
$images[] = $file;
}
}
closedir($handle);
return $images;
}
function dropdown($options_array, $selected = null)
{
$return = null;
foreach($options_array as $option)
{
$return .= '<option value="'.$option.'"'.
(($option == $selected) ? ' selected="selected"' : null ).
'>'.$option.'</option>'."\n";
}
return $return;
}
if (isset($_POST['submit'])) {
echo '<img src=images\\'. $_POST['image'] . ' />'; // changed here
}
?>