简体   繁体   English

Codeigniter-多次上传和文件信息

[英]Codeigniter - multiple uploads and file info

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. 大家好,我使用的是一个名为uploadify的jQuery上传器,它通过使用hardrive的flash multipicker,使用javascript将多个文件上传到服务器。 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. 即使您选择了多个项目,它也会使用ajax调用相同的脚本来分别上传文件。 This would allow me to write a php function in a controller that I named upload to upload that file. 这将允许我在名为上载的控制器中编写php函数来上载该文件。

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. 问题是我是Codeigniter的新手,并且想使用文件上传类,但据我所知,在进行上传之前,您无法找到文件的类型。 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. 我认为解决此问题的另一种方法是为每种上传类型创建一个单独的上传字段,然后仅调用一个不同的ajax脚本。 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. 我知道codeigniter使用name ='userfile'进行上传,我需要在页面上的三个上载器字段中使用不同的名称。 Can you have multiple upload fields per page with code igniter. 您是否可以使用代码点火器在每个页面上有多个上传字段。

If someone could help me out with this I would be greatly appreciated. 如果有人可以帮助我,我将不胜感激。

Why not just use mime types to determine what kind of file it is? 为什么不仅仅使用mime类型来确定文件类型呢? Uploadify has a problem where it doesn't specify what type of file it is, since it's using Flash-based upload. Uploadify的问题是,由于使用基于Flash的上传,因此未指定文件类型。

What I would reccomend, is after file is uploaded, check for mime type, and change directory based on what it is. 我建议,是在文件上传之后,检查mime类型,然后根据其内容更改目录。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM