2 w352546881 w352546881 于 2016.03.14 17:26 提问

[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.';
}

}
?>


4个回答

showbo
showbo   Ds   Rxr 2016.03.14 17: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

w352546881
w352546881 增加了 '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); 显示文件上传成功,但是在文件夹内还是木有额
接近 2 年之前 回复
qq_21792169
qq_21792169   2016.03.14 21:56

好好看下你代码中的路径

w352546881
w352546881   2016.03.15 17:10

增加了 '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);

显示文件上传成功,但是在文件夹内还是木有额

@无聊码农
w352546881
w352546881   2016.03.15 17:35

解决了,确实是路径问题
添加了onuploadsuccess 事件看到的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!