我想在目錄中添加圖片。該目錄是動態生成的。但上傳目錄和圖像中的圖像時出現錯誤,由於此錯誤而無法上傳,錯誤如下:在php上傳圖片
警告:mkdir():文件存在於C:\ wamp \ www \ test \ index中.PHP第21行
我的代碼是在這裏:
<body>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="filename" id="filename" />
<input type="submit" name="pic" />
</form>
</body>
</html>
<?php
if(isset($_POST['pic'])){
$comimages = $_FILES['filename']['tmp_name'];
$targetpath = mkdir("pageimage/pageid");
$compath = $targetpath."/".$_FILES['filename']['name'];
$comFileType=$_FILES['filename']['type'];
$comFileSize=$_FILES['filename']['size'];
$comFileSize=$comFileSize/1024;
if($comFileSize<1000)
{
$arrFileType=array("image/jpeg","image/png","image/gif","image/bmp");
if(in_array($comFileType,$arrFileType))
{
move_uploaded_file($comimages,$compath);
}
else
{
echo("invalid file format");
}
}
else
{
echo("File Size Error");
}
}
?>
嘗試使用is_dir(「pageimage /的pageid」)創建目錄之前 –