gpt4 book ai didi

php - 使用 uploadify 上传文件时出现 HTTP 500 错误

转载 作者:可可西里 更新时间:2023-10-31 23:48:08 26 4
gpt4 key购买 nike

我一直卡在上传部分。我正在使用上传脚本。普通文件已成功上传,但当我厌倦了上传一个名为 file's.jpg 的文件时,出现了 HTTP 500 错误。我的上传脚本是:

<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
$('#attachment').uploadify({
'uploader' : '<?php echo base_url();?>web/uploadify/uploadify.swf',
'script' : '<?php echo base_url();?>web/uploadify/uploadify.php',
'cancelImg' : '<?php echo base_url();?>web/uploadify/cancel.png',
//'folder' : '../../uploads/project_files/',
'folder' : '/admin_panel_new/assets/plupload/uploads/',
'auto' : true,
'multi' : true,
'hideButton': false,
'buttonImg' : "<?php echo base_url()?>images/attachment_image.gif",
'width' : 132,
'height' : 25,
'removeCompleted' : false,
'onSelect' : function(file) {
$('#submitFeedback').val('Please wait while uploading...');
$('#submitFeedback').attr('disabled','disabled');
},
'onComplete' : function(event, ID, fileObj, response, data) {
if($('#fileList').val()!='')
$('#fileList').val($('#fileList').val()+','+response);
else
$('#fileList').val(response);
//alert($('#fileList').val());

$('#submitFeedback').removeAttr('disabled');
$('#submitFeedback').val('Post Feedback');
},
'onError' : function(event, queueID, fileObj, errorObj) { alert(errorObj.type + ' ' + errorObj.info ); }
});
});
</script>

我尝试过许多其他解决方案,但都不走运。

我的 uploadify.php 代码是:

<?php
$targetFolder = $_POST['targetFolder']; // Relative to the root
$unik =$_POST['timestamp'];

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/'.$unik.'_'.$_FILES['Filedata']['name'];

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png','txt'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
//
echo $unik.'_'.$_FILES['Filedata']['name'];
} else {
echo 'Invalid file type. Upload Failed';
}
}
?>

上传错误图片是这样的 enter image description here

如果有人有解决办法请帮忙。谢谢。

最佳答案

如果问题只出现在使用单引号的文件名上,我会首先查看

$_FILES['Filedata']['name']

由于您连接的是未转义的输入字符串,因此单引号很可能会导致 move_uploaded_file 失败。 This thread演示了类似的问题。

我可能只是在存储文件名之前从文件名中删除单引号。或者尝试 addslashes

$targetFile = rtrim($targetPath,'/') . '/'.$unik.'_'.str_replace("'","",$_FILES['Filedata']['name']);

关于php - 使用 uploadify 上传文件时出现 HTTP 500 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22783762/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com