【问题标题】:php files upload (image and flash files) issuephp 文件上传(图像和 Flash 文件)问题
【发布时间】:2011-12-13 07:02:35
【问题描述】:

在处理文件上传任务时,我使用 jQuery 和 php 将文件上传到服务器以减少 http 请求的数量。从管理控制面板一切都很好,除了文件上传。文件上传在 localhost 中正常工作,但是当我在实时服务器环境中处理此文件时,文件没有被上传。我已将文件权限更改为 0777。

设置为777或上传游戏后,奇怪的东西权限会自动更改为755。

其实流程是: - 我将两个文件(即图像和 .swf 文件)存储在一个目录中 - 使用其数据库表 ID 创建目录 - 游戏文件和游戏图片没有上传到相应目录

例如,游戏 ID 342 使用名为 342 的目录名称创建,但图像和 swf 文件未上传到该目录中。对于每个游戏,都会使用游戏 ID 创建相应的目录。

我的代码: 文件名:uploadify.php

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

        $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
        $fileTypes  = str_replace(';','|',$fileTypes);
        $typesArray = split('\|',$fileTypes);
        $fileParts  = pathinfo($_FILES['Filedata']['name']);

            mkdir(str_replace('//','/',$targetPath), 0755, true);
            move_uploaded_file($tempFile,$targetFile);
            chmod($targetFile,0777);
            echo "1";

    }

jQuery 文件:js.js

$('#fileinput').uploadify({
        'uploader'  : 'uploader/uploadify.swf',
        'script'    : 'uploader/uploadify.php',
        'cancelImg' : 'uploader/cancel.png',
        'auto'      : true,
        'folder'    : "../../../games/"+$("#newgameid").val()+"/",
        'onComplete' : function(event,queueID,fileObj){
            $("#flashfileupload").html("file<strong>: "+ fileObj.name + " ("+ Math.round(fileObj.size/1000) + " kb)</strong> has been uploaded successfully!");    
            $("#size").val(Math.round(fileObj.size/1000));
            $("#filename").val(fileObj.name);
            $("#submitgame").removeAttr("disabled");
        },
        'onOpen' : function(event,queueID,fileObj){
            if(fileObj.name.indexOf(".swf")==-1){
                alert('Error Input - Flash game must SWF File!')
                $('#fileinput').uploadifyClearQueue();
            }
        }


    });


    $('#thumnail').uploadify({
        'uploader'  : 'uploader/uploadify.swf',
        'script'    : 'uploader/uploadify.php',
        'cancelImg' : 'uploader/cancel.png',
        'auto'      : true,
        'folder'    : "../../../games/"+$("#newgameid").val()+"/",
        'onComplete' : function(event,queueID,fileObj){
            $("#thumnailfileupload").html("file<strong>: "+ fileObj.name + " ("+ Math.round(fileObj.size/1000) + " kb)</strong> has been uploaded successfully!");
            $("#thumbnail").val(fileObj.name);
        }

    });

请在这方面帮助我。感谢您花时间阅读此问题。接受任何建议。

问候, phphunger.

【问题讨论】:

    标签: php jquery file-upload uploadify


    【解决方案1】:

    您的 mkdir() 函数调用将权限设置为 0755:

    mkdir(str_replace('//','/',$targetPath), 0755, true);
    

    尝试将其设置为 777:

    mkdir(str_replace('//','/',$targetPath), 0777, true);
    

    【讨论】:

    • 嗨,伦敦,感谢您的回复。我已经更改了它,但是创建了文件夹,但其中没有图像和闪存内容,而是文件夹权限保持 0755。即使我尝试将其更改为 0777,更改也不会应用于它。即使我也无法手动上传文件..
    • 作为健全性检查,您是否确保您的 php.ini 允许上传您尝试的大小?您可以显示 $_FILES 或 $targetFile 的任何调试输出吗?
    • 实际上该过程在 localhost 中运行良好,但在 ftp 上传时出现问题。无论如何,我有一个 .htaccess 文件,可以看到以下代码限制不上传文件。代码为 php_value post_max_size 80M php_value upload_max_filesize 80M php_value max_execution_time 120
    • 你能确保你的 php 文件归一个可以在新文件夹上设置 777 权限的用户所有吗?这听起来像是代码问题之前的配置/权限问题。
    • 意味着我没有得到你。对新文件夹设置 777 权限是什么意思?实际上我已将文件夹设置为 777,但它会自动将新创建的文件夹更改回 755。
    猜你喜欢
    • 2010-12-06
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    相关资源
    最近更新 更多