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 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?