Uploadify:写完成但没有上传文件

时间:2012-09-07 08:12:07

标签: php javascript jquery upload uploadify

我希望使用uploadify v.3.1(flash)上传图片。我点击选择文件,选择一个文件,文件上传但最后我收到错误信息:

haus2.jpg (256KB) - HTTP Error (401)

php.ini设置:

memory_limit: 256M
upload_max_filesize: 40M
post_max_size: 8M

我的php文件,我使用uploadify:

<script type="text/javascript">
    $(document).ready(function(){
        $(function() {
            $('#image_upload1').uploadify({
                'swf'            : '/project/swf/uploadify.swf',
                'uploader'       : '/project/includes/uploadify.php',
                'cancelImg'      : '/project/images/static/uploadify-cancel.png',
                'folder'         : '/project/images/uploaded/<?php echo $_SESSION['newCreatedID']; ?>',
                'multi'          : true,
                'auto'           : true,
                'removeCompleted': false,
                'queueSizeLimit' : 10,
                'simUploadLimit' : 10,
                'fileExt'        : '*.jpg; *.jpeg; *.png; *.gif',
                'fileDesc'       : 'JPG Image Files (*.jpg); JPEG Image Files (*.jpeg); PNG Image Files (*.png), GIF (*.gif)',
                '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>

<form action="step2_do.php" name="newEntry" id="newEntry" method="post" enctype="multipart/form-data">
    <input id="image_upload1" name="image_upload1" type="file" />
    <input type="submit" value=" Submit" id="submit-btn" class="inputform" />
</form>

没有抛出任何错误。

但没有错误。在Firebug中,从未显示过错误。上传的文件夹有777个权限,我删除了那里的建议.htaccess

uploadify.php

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

    mkdir(str_replace('//','/',$targetPath), 0777, true);
    move_uploaded_file($tempFile,$targetFile);
    echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
}

我找不到任何错误。我的调试可能性是什么?

我没有任何错误
error_reporting(E_ALL);
ini_set("display_errors", 1);

修改

现在我完全忘记了需要密码才能访问该网站的htaccess。现在fileupload写完了,但服务器上没有文件夹/文件。我实现了onUploadSuccess,它给我带来了以下错误消息:

The file haus.jpg was successfully uploaded with a response of true:<br />
<b>Warning</b>:  mkdir() [<a href='function.mkdir'>function.mkdir</a>]: File exists in <b>/home/myuser/www/home/project/includes/uploadify.php</b> on line <b>21</b><br />
/haus.jpg

主要问题是我将旧版的uploadify与新的API混合在了一起。对于我使用的调试:

$request = implode(";", $_REQUEST);
file_put_contents('uploadify.txt', chr(10) . ": request" . $request, FILE_APPEND);

我的最终初始化如下:

$(document).ready(function(){
    $(function() {
        $('#image_upload1').uploadify({
            'swf'            : '/project/swf/uploadify.swf',
            'uploader'       : '/project/includes/uploadify.php',
            'formData'       : {'folder' : '/project/images/uploaded/<?php echo $_SESSION['newCreatedID']; ?>'},
            'multi'          : true,
            'auto'           : true,
            'removeCompleted': false,
            'queueSizeLimit' : 10,
            'simUploadLimit' : 10,
            'fileTypeExt'        : '*.jpg; *.jpeg; *.png; *.gif',
            'fileTypeDesc'       : 'JPG Image Files (*.jpg); JPEG Image Files (*.jpeg); PNG Image Files (*.png), GIF (*.gif)',
            '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);
            }
        });
    });
});
应该使用

formData ......

1 个答案:

答案 0 :(得分:2)

401表示用户需要在上传之前进行身份验证。

您可以尝试在参数列表中发回$ .cookie('sessionid'),以确保它知道正在进行上传的会话。