我正在尝试上传图片,但我甚至没有在我的内容中返回“hi”消息...这是HTML:
<form action="" enctype="multipart/form-data" method="post" id="form_c">
<label for="title">Title:</label>
<input type="text" name="title" id="title"/>
<label for="content">Content:</label>
<textarea name="content" id="content"></textarea>
<label for="date">Release Date (RRRR-MM-DD):</label>
<input type="text" name="date" id="date"/>
<label for="price">Price:</label>
<input type="text" name="price" id="price"/>
<label for="album_img">Price:</label>
<input type="file" name="album_img" id="album_img"/>
<span>
<?php
if (isset($_POST['btn_submit'])) {
require_once "/../../controllers/admin/File_Handler.php";
$file_handle = new File_Handler;
$file_handle->uploadImg();
}
?>
</span>
<button type="submit" name="btn_submit">Submit</button>
</form>
这是PHP:
<?php
Class File_Handler {
private $file_temp;
private $file_name;
private $file_size;
private $file_type;
// Max size 2mb
private $max_size = 2000000;
private $target_path = "../../images/";
public function __construct () {
$this->file_temp = $_FILES['album_img']['tmp_name'];
$this->file_name = $_FILES['album_img']['name'];
$this->file_size = $_FILES['album_img']['size'];
$this->file_type = $_FILES['album_img']['type'];
$this->target_path += $this->file_name;
}
public function setMaxSize ($size) {
$this->max_size = size;
}
public function uploadImg () {
return "hi";
if ($this->file_size > $this->max_size) {
return "file size too big";
}
else if (move_uploaded_file($this->file_temp, $this->target_path)) {
return "The image ". $this->file_name . " has been uploaded successfully!";
}
else {
return "There was an error uploading the image, please try again!";
}
}
}
我认为php甚至没有关闭,因为它似乎正在做的就是刷新页面。这可能是愚蠢的事,但我无法弄明白!