我正在尝试创建一个用于存储照片的管理面板目录创建器。我遵循了一个教程,但是根据我的喜好对其进行了调整,尽管目录创建得很好,但我无法上传文件。这是代码,你能提示我做错了什么吗?如果我正在接近这个最好的方法吗?我并不完全相信将路径设置为 '../../../' 是最好的方法。
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<label>Album name:</label><span class="req">*</span>
<br />
<input type="text" name="album_name">
<br />
<input type="file" name="upload" /><br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<input type="submit" name="submit" value="Create">
</form>
<?php
if(isset($_POST['submit'])){
$album = $_POST['album_name'];
if(mkdir("../images/album/" . $album, 0700, true) && mkdir("../images/album/" . $album . "/album_cover", 0700, true)){
echo "Album directory created successfully";
}else{
echo "Album directory failed";
}
}
$target_path = "../images/album/" . $album . "/album_cover/";
$target_path = $target_path . basename( $_FILES['upload']['name']);
if(move_uploaded_file($_FILES['upload']['name'], $target_path)){
echo "The file ". basename($_FILES['upload']['name']) . " has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
?>