【发布时间】:2014-03-23 01:36:54
【问题描述】:
我想将uploadify 用于图像以外的其他文件类型,但我无法让它工作。它可以毫无问题地上传任何类型的图像。当我尝试上传其他任何内容时,指示器显示 100%,但上传文件夹中没有可找到的文件(只有图片)。
index.php 文件:
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'checkExisting' : '/Bcp/uploadify/check-exists.php',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'fileSizeLimit' : '50000KB',
'fileTypeExts' : '*.gif; *.jpg; *.png; *.png; *.mp3',
'fileTypeDesc' : 'Images and music'
});
});
</script>
uploadify.php 文件:
$targetFolder = '/bcp/uploadify/uploads_pics'; // 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','jpeg','gif','png', 'mp3'); // 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.';
}
}
总结
上传图片 - 是的,没问题
上传其他任何东西 - 不,为什么以及如何让它工作?
提前致谢。
【问题讨论】:
标签: php file-upload upload uploadify