dtoqemais553654797 2012-09-07 08:12
浏览 48
已采纳

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

I want upload images with uploadify v.3.1 (flash). I click on select files, choose a file, the file is uploaded but in the end I get the error message:

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

php.ini settings:

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

My php file where I use 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>

There is no error thrown.

But there is no error. In Firebug there is never an error shown. The uploaded folder has 777 rights and I removed the proposed .htaccess in there.

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);
}

I cannot find any error. What are my possibilites to debug?

I don't get any errors with

error_reporting(E_ALL);
ini_set("display_errors", 1);

Edit:

Now I completely forgot about a htaccess needing a password for accessing the site. Now fileupload is writing complete but there is no folder/files on the server. I implemented onUploadSuccess which brings me the following error message:

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

The main problem was that I mixed up the old API of uploadify with the new one. For debugging I used:

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

My final initialization looks like:

$(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 should be used ...

  • 写回答

1条回答 默认 最新

  • duanmao9918 2012-09-07 08:17
    关注

    401 suggests that the user needs to be authenticated before uploading.

    You might try sending back your $.cookie('sessionid') in the parameter list, to make sure it knows what session is doing the upload.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥60 SOL语句中Where查询中的 from to 语句能不能从小到大换成从大到小(标签-SQL)
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 请教一下c语言的代码里有一个地方不懂
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))