我有文件上传问题。当尝试将文件发送到我的本地服务器时,我得到“301 Moved Permanently”作为POST的响应。上传目录中没有创建文件。下面是index.php和upload.html的代码。 $ base_url指向localhost / testpage
[的index.php]
$app->get('/upload/', function() use ($app) {
global $base_url;
return $app->render('upload.html', array('base_url' => $base_url));
});
$app->post('/upload/', function() use ($app) {
$imagename = $_FILES['image']['name'];
$unique_id = md5(uniqid(rand(), true));
$filetype = strrchr($imgname, '.');
$new_upload = 'upload' . $unique_id . $filetype;
move_uploaded_file($_FILES['image']['tmp_name'], $new_upload);
//$the_upload = copy($_FILES['image']['tmp_name'], $new_upload);
//@chmod($new_upload, 0777);
$app->redirect('/');
})
[upload.html]
<html>
<body>
<form action="{{base_url}}/upload" method="POST">
<input type="file" name="photo" value="" id="image" />
<input type="submit" value="Upload image" />
</form>
</body>
答案 0 :(得分:0)
你应该在$ _FILES数组中引用'photo'而不是'image'。输入标记的id字段不是在表单数据中发送的,它仅由浏览器使用。