2014-02-21 2 views
-2

안녕라는 이미지글롭 기능 출력은 모든 파일

<?php 
//Path to folder which contains images 
$dirname = $_POST['dir']; 

//Use glob function to get the files 
//Note that we have used " * " inside this function. If you want to get only JPEG or PNG use 
//below line and commnent $images variable currently in use 
$images = glob($dirname."*"); 

//Display image using foreach loop 
foreach($images as $image) { 

//print the image to browser with anchor tag (Use if you want really :)) 
echo '<p><img style="height:176px; width:221px; float:right;" src="'.$image.'" /></p>'; 
} 
?> 
파일에서 출력 이미지에이 코드를 사용하고는

나는 image.php라고 나는 사용자가 디렉토리

을 선택하려면이 양식을 사용
<form method="POST" action="image.php"> 
<input type="text" name="dir" placeholder="choose directory" /> 
<input type="submit" value="choose" /> 
</form> 

코드를 실행할 때 폴더에있는 모든 파일을 출력합니다. test.php와 같은 파일과 js 및 css 파일 및 이미지라는 이미지가있는 파일은 js 및 css 및 all .php 출력을 실행할 때 발생합니다. 파일에 이미지가 출력되지 않습니다. 오류 :

+0

가능한 중복 http://stackoverflow.com/questions/19543136/php -foreach-and-glob-function) –

답변

1

매우 위험합니다. 누구든지 원하는 폴더를 입력하고 해당 디렉토리의 모든 파일을 즉시 볼 수 있습니다 (PHP 파일의 경우 실행). "오직 JPEG 또는 PNG 원하는"에 대한 코드에서 주석이 잘 당신이 할 수있는

참고 :

$images = glob($dirname."*.{png,jpg,jpeg,gif}",GLOB_BRACE); 

이 유형 만의 이미지 파일을 수 있습니다.

또한 glob은 재귀가 아닙니다. 디렉토리를 통해 수동으로 재귀해야합니다.

0

또는이, 당신은 확장을 필터링하지 않으려면 :

//Path to folder which contains images 
$dirname = $_POST['dir']; 

//Use glob function to get the files 
//Note that we have used " * " inside this function. If you want to get only JPEG or PNG use 
//below line and commnent $images variable currently in use 
$images = glob($dirname."/"."*"); 

//Display image using foreach loop 
foreach($images as $image) { 

//print the image to browser with anchor tag (Use if you want really :)) 
echo '<p><img style="height:176px; width:221px; float:right;" src="'.$image.'" /></p>'; 
} 
[PHP의 foreach 문 및 글로브() 함수 (의