0
사진 저장을위한 관리자 패널 디렉토리 작성자를 만들려고합니다. 나는 튜토리얼을 따라 갔지만, 나의 취향에 맞추어서 조정할 수 있었고, 파일을 업로드 할 수 없었다. 여기에 코드가 있는데, 내가 잘못한 것을 암시 할 수 있겠습니까? 제가 가장 좋은 방법으로 접근하고 있다면 요? 나는 '../../../'이 최선의 접근 방식이라는 점을 전적으로 확신하고있는 것은 아닙니다.PHP_SELF 양식으로 파일 업로드
<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!";
}
?>
이것은 효과가 있습니다. 정말 고마워요. 이 코드를 작성 했습니까? 그것들 중 하나를 별도로 배치해야합니까? –
코드가 좋아 보인다. –