w352546881 2016-03-14 09:26 采纳率: 100%
浏览 1771
已采纳

[php]uploadify 无法上传文件 初学

本人初学uploadify上传,使用给的demo无法将文件上传到uploads文件夹内
请各位大神给予指导
index.php

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UploadiFive Test</title>
<script src="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="uploadify" name="uploadify" type="file" multiple="true">
    </form>
        <a href="javascript:$('#uploadify').uploadify('upload')" >upload</a>
    <script type="text/javascript">
        <?php $timestamp = time();?>
        $(function() {
            $('#uploadify').uploadify({
                'formData'     : {
                    'timestamp' : '<?php echo $timestamp;?>',
                    'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                },
                'swf'      : '/php_test/uploadify/uploadify.swf',
                'uploader' : '/php_test/uploadify/uploadify.php',
                'folder'   : '/php_test/uploadify/uploads'
            });
        });
    </script>
</body>
</html> 

uploadify.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

$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'); // 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.';
}

}
?>


  • 写回答

3条回答 默认 最新

  • 斯洛文尼亚旅游 2016-03-14 09:36
    关注

    swf和uploader配置对了吗?jquery和uploadify的js路径对了没有

    按照你的配置网站更目录下要存在php_test/uploadify/这个路径,添加onUploadSuccess和onUploadError事件看有什么错误,并且你请求的文件也要在php_test/uploadify/下

       $(function() {
            $('#uploadify').uploadify({
                'formData'     : {
                    'timestamp' : '<?php echo $timestamp;?>',
                    'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
            },
                'swf'      : '/php_test/uploadify/uploadify.swf',
                'uploader' : '/php_test/uploadify/uploadify.php',
                'folder'   : '/php_test/uploadify/uploads', 
                'onUploadError' : function(file, errorCode, errorMsg, errorString) {   //上传错误   
                            alert('The file ' + file.name + ' could not be uploaded: ' + errorString);   
                 }
          });
        });
    

    uploadify api

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?