本文介绍了Uploadify FOLDER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Uploadify上传文件并使用Codeigniter框架。

I am using Uploadify to upload Files and using Codeigniter framework.

这是我的Uploadify代码:

Here is my Uploadify code :

$("#change_profile_icon").uploadify({

                    'uploader'       : '/project/style/scripts/crop/uploadify/uploadify.swf',
                    'script'         : 'http://localhost/project/pages/profile_icon',
                    'cancelImg'      : '/project/style/scripts/crop/uploadify/cancel.png',
                    'buttonText'     :'Upload image',
                    'width'          : '110',
                    'height'         : '30',
                    'queueID'        : 'fileQueue',
                    'auto'           : true,
                    'scriptData'     :{username :"<?php echo $this->session->userdata('username');?>",folder:"honda"},
                    'queueSizeLimit' : 1,
                    'multi'          : false,
                    'fileDesc'       : 'jpg',
                    'fileExt'        : '*.jpg;*.png',
                    'sizeLimit'      : '819200',//max size bytes - 800kb
                    'onComplete'     : function(event,queueID,fileObj,response,data) {
                                            alert("Completed");
                                            var dataresponse = eval('(' + response + ')');
                                            //$('#uploadifyUploader').remove();
                                        var filenametmp = "http://localhost"+(dataresponse.file).substring(0,(dataresponse.file).lastIndexOf("?"));
                                        var current_page = $('#page-list').val();

                                        },

                                        'onSelect' : function (){
                                        var folder =  $('#page-list option:selected').text(); //returns HONDA which is correct
$('#change_profile_icon').uploadifySettings('folder',folder);
}   ,           
                    'onError'        : function(){
                                            alert('error');
                                       }
                });

这是我的PHP部分[Uploadify中的脚本值]

Here is my PHP part [script value in Uploadify]

function profile_icon()
    {
    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_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']);

    // if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        $targetPath = 'uploads/' .$_REQUEST['folder']. '/';
        $targetFile = $targetPath.$_FILES['Filedata']['name'];
        if (!file_exists($targetPath))
        {
         mkdir(str_replace('//','/',$targetPath), 0755, true);
        }
        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    // } else {
    //  echo 'Invalid file type.';
    // }
}

问题:

$targetPath = 'uploads/' .$_REQUEST['folder']. '/';
            $targetFile = $targetPath.$_FILES['Filedata']['name'];
            if (!file_exists($targetPath))
            {
             mkdir(str_replace('//','/',$targetPath), 0755, true);
            }

检查从PHP部分获取的上述代码。我认为 $ _ REQUEST ['folder'] 将给出在Uploadify脚本中指定的文件夹名称。文件夹的值为<$

Check the above codes taken from the PHP part.I think that $_REQUEST['folder'] will give the folder name which is specified on the Uploadify script.The value of folder is HondaBut this gives something different.

我上传了一个文件,这个脚本上传到

I uploaded a file and this script uploaded it to

C:\wamp\www\project\uploads\project\home\editpage\honda\honda

在wamp伺服器上[我在Localhost]

On wamp server [I am in Localhost]

但是怎么会呢?它应该是

But how it comes ?? it should be

 C:\wamp\www\project\uploads\honda

请检查下列...

  $targetPath = 'uploads/' .$_REQUEST['folder']. '/';
  $targetFile = $targetPath.$_FILES['Filedata']['name'];

targetPath $ c> uploads / honda /
targetFile 现在应为 uploads / honda / fileName.ext

The targetPath should be now uploads/honda/and targetFile should be now uploads/honda/fileName.ext

我不知道我做错了什么,在哪里是....

I dont know what i am doing wrong and where it is....

请帮助我。

谢谢。

当前页面结构: http:// localhost / Project / home / editpage / honda /
其中首页是一个控制器, editpage 是一个函数, honda 是一个参数[Codeigniter framework]

EDIT : THE URL STRUCTURE OF CURRENT PAGE : http://localhost/Project/home/editpage/honda/Where home is a controller and editpage is a function and honda is a argument.[Codeigniter framework]

SOLVED

我解决了这个问题,它是uploadify中的一个错误:uploadify文件夹变量不直接,所以我们应该添加一个 slash 之前。

I solved the issue,it is a bug in uploadify : The uploadify folder variable is not straight forward ,so that we should add a slash before that.

所以它会是 var folder =/+FolderName;
问题是如果u只使用文件夹名称,就无法返回服务器上的数据。

so it would be var folder = "/"+ "FolderName";The problem is u cant return the data on server if u use just Folder name.

推荐答案

我解决了问题, uploadify文件夹中的一个错误:uploadify文件夹变量不直接,所以我们应该在之前添加一个斜杠。

I solved the issue,it is a bug in uploadify : The uploadify folder variable is not straight forward ,so that we should add a slash before that.

因此它将是var folder =/ 文件夹名称;问题是无法返回服务器上的数据,如果你只使用文件夹名称。

so it would be var folder = "/"+ "FolderName"; The problem is u cant return the data on server if u use just Folder name.

这篇关于Uploadify FOLDER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 21:35