2

我的文件上传有问题。当尝试将文件发送到我的本地服务器时,我得到“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>
4

1 回答 1

0

您应该在 $_FILES 数组中引用“照片”而不是“图像”。输入标签的 id 字段不会在表单数据中发送,它仅由浏览器使用。

于 2014-03-16T09:55:36.313 回答