过去6天我一直忙于多个文件上传。我找到了uploadify并尝试了免费版本。没有工作,所以我买了uploadifive。仍然没有成功。即使我对代码没有任何改动,只是在我得到它时实现它,也不会上传文件。我没有收到任何错误,上传栏达到了100%。我的uploadfolder保持空白。我已根据建议将chmod权限设置为755,并尝试了777.我尝试更改$ _SERVER ['DOCUMENT_ROOT']。 $ targetFolder到绝对路径。当我回显Document_Root时,它只给出/ htdocs。我把它放在哪个文件夹中并不重要。
我对此失去了理智,不知道如何解决这个问题。我在下载后发布了index.php和uploadifive.php的代码:
的index.php
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
<a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>
</form>
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadifive({
'auto' : false,
'checkScript' : 'check-exists.php',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'queueID' : 'queue',
'uploadScript' : 'uploadifive.php',
'onUploadComplete' : function(file, data) { console.log(data); }
});
});
</script>
uploadifive.php
// Set the uplaod directory
$uploadDir = '/uploads/';
// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
$targetFile = $uploadDir . $_FILES['Filedata']['name'];
// Validate the filetype
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
// Save the file
move_uploaded_file($tempFile, $targetFile);
echo 1;
} else {
// The file type wasn't allowed
echo 'Invalid file type.';
}
}
有谁看到这里会出现什么问题?
答案 0 :(得分:1)
这是$ _SERVER ['DOCUMENT_ROOT']。删除它只用rootfolder替换它就可以了。
调整后的代码:
// Set the upload directory
$uploadDir = '/uploads/';
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadDir = '../htdocs'. $uploadDir;
$targetFile = $uploadDir . $_FILES['Filedata']['name'];
感谢您的帮助:)
答案 1 :(得分:0)
我写了更多的错误检查。
尝试此代码并打开控制台并检查uploadifive.php
返回的内容。
// Set the uplaod directory
$uploadDir = '/uploads/';
// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
$targetFile = $uploadDir . $_FILES['Filedata']['name'];
// Validate the filetype
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
// Save the file
if(move_uploaded_file($tempFile, $targetFile)) {
echo 1;
} else {
echo "Cant move file on path: " . $targetFile;
}
} else {
// The file type wasn't allowed
echo 'Invalid file type.';
}
} else {
echo '$_FILES is empty or token is invalid';
}