我是一个编程新手,我正尝试在我的网站上使用uploadify。上载文件后,我收到一条成功消息,但文件未上载到文件夹。我试着用我在stackoverflow上找到的所有答案来调试代码,但似乎什么都不起作用。下面是index.php的代码
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<hr>
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="uploadify.css">
<style type="text/css">
body {
font: 13px Arial, Helvetica, Sans-serif;
}
</style>
</head>
<body>
<h1>Uploadify Demo</h1>
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
</form>
<?php $timestamp=t ime();?>
<script type="text/javascript">
$(function() {
$("#file_upload").uploadify({
'uploader': 'uploadify.swf',
'cancelImg': 'uploadify-cancel.png',
'buttonText': 'Browse Files',
'script': 'uploadify.php',
'folder': '/uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'queueSizeLimit': 9999,
'simUploadLimit': 2,
'sizeLimit': 4000000,
'checkExisting': false,
'multi': true,
'formData': {
'timestamp': '<?php echo $timestamp;?>',
'token': '<?php echo md5("unique_salt" . $timestamp);?>'
},
'auto': true,
'onUploadError': function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
},
'onUploadSuccess': function(file, data, response) {
alert('The file ' + file.name + ' was successfully uploaded with a response of ' /*+ response +*/ + ':' + data);
},
});
});
</script>
</body>
</html>
这是uploadify.php文件
<?php
// Define a destination
$targetFolder = '/uploads'; // Relative to the root
$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,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','JPG','jpeg','JPEG','gif','GIF','png','PNG'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>
check-exists.php s.php文件
<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
// Define a destination
$targetFolder = '/uploads'; // Relative to the root and should match the upload folder in the uploader script
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $targetFolder . '/' . $_POST['filename'])) {
echo 1;
} else {
echo 0;
}
?>
PS:我尝试过将$targetFolder更改为uploads,/uploads,/uploads/,但都不起作用。该文件夹有777个权限,我得到的成功消息是“文件________已成功上传,响应为: CWSaa”我不知道CWSaa是什么,也不知道它是如何回显的。
请帮帮忙。
发布于 2015-05-02 14:23:46
似乎是文件夹路径的问题,你是usig ' folder ':'/uploads‘。这意味着上传文件夹在文档根目录中。如果文件夹和代码文件在同一个位置,那么你需要使用' folder ':'uploads‘。
一定要检查你在php中定义的其他路径。
https://stackoverflow.com/questions/29998232
复制相似问题