2012-11-13 100 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); 

它應該只是罰款。