我的文件上传有问题。当尝试将文件发送到我的本地服务器时,我得到“301 永久移动”作为 POST 的响应。上传目录中没有创建文件。下面是 index.php 和 upload.html 的代码。$base_url 指向 localhost/testpage
[索引.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('/');
})
[上传.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>