我想创建一个表单,我可以将文件上传到目录。如果它不存在我将创建它。我想选择自己应该放在哪里。
<?php
$root = $_SERVER["DOCUMENT_ROOT"];
$url_link = "/gpsupload/tour/";
$dist = $root . $url_link;
if(!is_dir($dist)) {
echo"Create dir!";
exit;
}
if(!is_writeable($dist)) {
echo "Tjek writable ". $dist ." !!!!!<br />";
exit;
}
?>
<body>
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
Select file:<br>
<input name="upfile" type="file"><br>
File upload to directory: <?php echo $dist; ?>
<br />
Or write name to new dir: <input type="text" name="newdir">
<br />
<input type="submit" value="Upload">
</form>
<?php
if (isset($_FILES["upfile"])) {
if(!empty($_POST["newdir"])) {
mkdir($dist . $_POST["newdir"], 0777);
chmod($dist . $_POST["newdir"], 0777);
$dist = $dist . $_POST["newdir"] ."/";
$url_link .= $_POST["newdir"] ."/";
}
if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $dist . $_FILES["upfile"]["name"])) {
echo"File, ". $_FILES["upfile"]["name"] ." is uploadet. <a href=\"". $url_link . $_FILES["upfile"]["name"] ."\">". $_FILES["upfile"]["name"] ."</a>";
}else{
echo"File is not uploadet?";
}
}
?>
</body>
如何选择我想要创建目录的位置?