Yii 不会 move_uploaded_file - 500 内部服务器错误
Yii will not move_uploaded_file - 500 internal server error
我正在使用带有 Yii 的 blueimp 文件上传插件来尝试将文件上传到我的服务器(当前是本地主机)。我给文件夹完全读/写权限(位置是C:\xampp\htdocs\yii),但是当我尝试执行move_uploaded文件命令时仍然出现错误。
这里是主窗体和输入文件区:
<form id='upload' method='post' action='?r=site/move' enctype='multipart/form-data' style="padding:0;">
<span class="btn fileinput-button" style="padding:0">
<i class="glyphicon glyphicon-picture">
<input id="fileupload" type="file" accept="image/*" name="attachment" onchange="attachAttachment()">
</i>
</span>
</form>
这里是 blueimp 的文件上传(在 function() 中):
$("#fileupload").fileupload
({
dataType: 'json',
done: function (e, data)
{
console.log("YAY");
},
fail: function(e, data)
{
console.log("FAIL");
}
});
这是 actionMove,我将文件从临时目录移动到文件夹:
public function actionMove()
{
if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == 0)
{
if (move_uploaded_file($_FILES['attachment'], Yii::getPathOfAlias('webroot')."/images/uploads")){
$response = '{"status":"success"}';
}
else {
$response = '{"status":"error"}';
}
echo $response;
exit();
}
}
我已经在这里工作了几个小时了,感谢任何帮助:(
$_FILES['attachment']
引用有关下载的所有数据。 move_uploaded_file
使用文件名来工作。这是您应该尝试的方法:
$uploadPath = Yii::getPathOfAlias('webroot')."/images/uploads";
$uploadFilename = basename($_FILES['attachment']['name']);
$tempFilename = $_FILES['attachment']['tmp_name'];
$ok = move_uploaded_file($tempFilename, $uploadPath.'/'.$uploadFilename);
if ($ok) {
$response = '{"status":"success"}';
} else {
$response = '{"status":"error"}';
}
文档页面上有更多相关信息:
http://php.net/manual/fr/features.file-upload.post-method.php
和
http://php.net/manual/fr/function.move-uploaded-file.php
希望对您有所帮助。
我正在使用带有 Yii 的 blueimp 文件上传插件来尝试将文件上传到我的服务器(当前是本地主机)。我给文件夹完全读/写权限(位置是C:\xampp\htdocs\yii),但是当我尝试执行move_uploaded文件命令时仍然出现错误。
这里是主窗体和输入文件区:
<form id='upload' method='post' action='?r=site/move' enctype='multipart/form-data' style="padding:0;">
<span class="btn fileinput-button" style="padding:0">
<i class="glyphicon glyphicon-picture">
<input id="fileupload" type="file" accept="image/*" name="attachment" onchange="attachAttachment()">
</i>
</span>
</form>
这里是 blueimp 的文件上传(在 function() 中):
$("#fileupload").fileupload
({
dataType: 'json',
done: function (e, data)
{
console.log("YAY");
},
fail: function(e, data)
{
console.log("FAIL");
}
});
这是 actionMove,我将文件从临时目录移动到文件夹:
public function actionMove()
{
if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == 0)
{
if (move_uploaded_file($_FILES['attachment'], Yii::getPathOfAlias('webroot')."/images/uploads")){
$response = '{"status":"success"}';
}
else {
$response = '{"status":"error"}';
}
echo $response;
exit();
}
}
我已经在这里工作了几个小时了,感谢任何帮助:(
$_FILES['attachment']
引用有关下载的所有数据。 move_uploaded_file
使用文件名来工作。这是您应该尝试的方法:
$uploadPath = Yii::getPathOfAlias('webroot')."/images/uploads";
$uploadFilename = basename($_FILES['attachment']['name']);
$tempFilename = $_FILES['attachment']['tmp_name'];
$ok = move_uploaded_file($tempFilename, $uploadPath.'/'.$uploadFilename);
if ($ok) {
$response = '{"status":"success"}';
} else {
$response = '{"status":"error"}';
}
文档页面上有更多相关信息: http://php.net/manual/fr/features.file-upload.post-method.php 和 http://php.net/manual/fr/function.move-uploaded-file.php
希望对您有所帮助。