dongyi1996 2011-09-08 19:26
浏览 66

Codeigniter - 多个上传和文件信息

Hello all I am using a jQuery uploader called uploadify which uploads multiple files to a server using javascript by having a flash multipicker for your hardrive. This makes it easy to grab a bunch of files all at once instead of one at a time. I have a problem. It would call the same script using ajax to upload the files individually even though you selected multiple items. This would allow me to write a php function in a controller that I named upload to upload that file.

I would like to be able to allow a user to upload all their files during their sign up process. The problem is that Im new to codeigniter and want to use the file upload class but as far as I know you cant find out what type of file it is before you make the upload. Only afterwards you can find out if it is an image or not. The reason for doing this is because I am putting them all in separate folders. One for videos one for music and one for images.

I thought another way around this was to create a seperate upload field for each type of upload and just call a differenct ajax script. This is actually what I would prefer to do but there is another problem. I know that codeigniter uses the name=‘userfile’ to do the upload and I need three uploader fields on my page with different names on them. Can you have multiple upload fields per page with code igniter.

If someone could help me out with this I would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dszm02606009 2011-09-09 00:28
    关注

    Why not just use mime types to determine what kind of file it is? Uploadify has a problem where it doesn't specify what type of file it is, since it's using Flash-based upload.

    What I would reccomend, is after file is uploaded, check for mime type, and change directory based on what it is.

    If it's just image or videos, then it's simple to do since there's only few different types.

    function new_mime_content_type($filename) {
    
        $mime_types = array(
    
                'txt' => 'text/plain',
                'htm' => 'text/html',
                'html' => 'text/html',
                'php' => 'text/html',
                'css' => 'text/css',
                'js' => 'application/javascript',
                'json' => 'application/json',
                'xml' => 'application/xml',
                'swf' => 'application/x-shockwave-flash',
                'flv' => 'video/x-flv',
    
                // images
                'png' => 'image/png',
                'jpe' => 'image/jpeg',
                'jpeg' => 'image/jpeg',
                'jpg' => 'image/jpeg',
                'gif' => 'image/gif',
                'bmp' => 'image/bmp',
                'ico' => 'image/vnd.microsoft.icon',
                'tiff' => 'image/tiff',
                'tif' => 'image/tiff',
                'svg' => 'image/svg+xml',
                'svgz' => 'image/svg+xml',
    
                // archives
                'zip' => 'application/zip',
                'rar' => 'application/x-rar-compressed',
                'exe' => 'application/x-msdownload',
                'msi' => 'application/x-msdownload',
                'cab' => 'application/vnd.ms-cab-compressed',
    
                // audio/video
                'mp3' => 'audio/mpeg',
                'qt' => 'video/quicktime',
                'mov' => 'video/quicktime',
    
                // adobe
                'pdf' => 'application/pdf',
                'psd' => 'image/vnd.adobe.photoshop',
                'ai' => 'application/postscript',
                'eps' => 'application/postscript',
                'ps' => 'application/postscript',
    
                // ms office
                'doc' => 'application/msword',
                'rtf' => 'application/rtf',
                'xls' => 'application/vnd.ms-excel',
                'ppt' => 'application/vnd.ms-powerpoint',
    
                // open office
                'odt' => 'application/vnd.oasis.opendocument.text',
                'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        );
    
        $ext = strtolower(array_pop(explode('.',$filename)));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[$ext];
        }
        else {
            return 'general/general';
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码