2
我有文件上傳問題。當試圖發送文件到我的本地服務器時,我得到「301永久移動」作爲POST的響應。上傳目錄中沒有創建文件。以下是index.php和upload.html的代碼。 $ BASE_URL點到localhost/testpageslim上傳的文件:301在POST響應中
[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>
你想要發生什麼?您上傳文件後發送重定向:'$ app-> redirect('/');' – drew010 2012-08-01 17:57:56
是的,但沒有重定向。它看起來像$ app-> post('/ upload /')永遠不會運行。它只會重新加載/上傳頁面。 – GeekDaddy 2012-08-01 18:00:23
檢查'move_uploaded_file'的結果,我認爲'$ new_upload'的路徑可能不可寫或可能需要一個完整路徑。那麼你是否還是在問題中提到的上傳時沒有收到「301 Moved Permanently」響應? – drew010 2012-08-01 18:10:28