2012-11-13 4 views
2

index.php를에서 mkdir() PHP 함수 문제

<html> 
    <body> 
     <form action="createfolder.php" method="post" > 
     <table width="400" border="0" cellspacing="0" cellpadding="5"> 
      <tr> 
      <td colspan="3" align="center">Please write gallery name and description</td> 
      </tr> 
      <tr> 
      <td>Name </td> 
      <td>&nbsp;</td> 
      <td><input type="text" name="gname" id="text" value=""></td> 
      </tr> 
      <tr> 
      <td>Description</td> 
      <td>&nbsp;</td> 
      <td><textarea name="gdescription" cols="30" rows="5" id="textarea"></textarea></td> 
      </tr> 
      <tr> 
      <td colspan="3" align="center"><input type="submit" name="submit" id="submit" value="Submit"></td> 
      </tr> 
     </table> 
     </form> 
    </body> 
</html> 

createfolder.php 디렉토리를 만드는

<?php 

$name = $_POST['gname']; 
$dirPath = "images/".$name; 
$result = mkdir($dirPath, 0755); 
if ($result == 1) { 
    echo $dirPath . " has been created"; 
} else { 
    echo $dirPath . " has NOT been created"; 
} 
?> 

하는 데 문제가. 오류 : this is the error

답변

1

의이 더

file_exists 디렉토리 사용자의 파일이 없기 때문에 - 파일이나 디렉토리가 존재하는지 여부를 확인하고

is_dir는 - 파일 이름이 디렉토리

if (is_dir("path") === true){ 
       echo "DIRECTORY: ".$entry."\n"; 
      } 
인지 아닌지 이야기하기

또는

$filename = '/path/foo.txt'; 

if (file_exists($filename)) { 
    echo "The file $filename exists"; 
} 
0

mkdir($dirPath, 0755, true);

세 번째 매개 변수는 포함 된 디렉터리도 재귀 적으로 만듭니다.

0

mkdir()에는 세 번째 인수 인 $recursive이 있으므로 전체 경로가 있는지 확인할 수 있습니다.

$result = mkdir($dirPath, 0755); 

로 :

$result = mkdir($dirPath, 0755, true); 

을 그리고 그것은 잘 작동합니다이를 교체합니다.