Welcome Guest, Not a member yet? Register   Sign In
Multi Upload with CI & swfUpload
#11

[eluser]Gabriel Popa[/eluser]
i founded the problem. it was
Code:
'application/octet-stream'
part of pdf mime time missing
#12

[eluser]Gabriel Popa[/eluser]
thank you ... a lot.. have a nice we.
#13

[eluser]Vlad0[/eluser]
Hi,
i have some session problems...
here is my view
Code:
.
.
<link rel="stylesheet" type="text/css" href="<?=base_url();?>assets/css/default.css">





        var swfu;

        window.onload = function() {
            swfu = new SWFUpload({
            //var settings = {
                flash_url : "<?=base_url();?>assets/js/swfupload_f9.swf",
                upload_url: "<?=base_url();?>index.php/projects/dominiuploadx",    // Relative to the SWF file
                post_params: {"PHPSESSID" : "<?=$this->session->userdata('session_id');?>"},
                file_size_limit : "64 MB",
                file_types : "*.*",
                file_types_description : "All Files",
                file_upload_limit : 100,
                file_queue_limit : 0,
                custom_settings : {
                    progressTarget : "fsUploadProgress",
                    cancelButtonId : "btnCancel",
                    load_target : "divFileProgressContainer"
                },
                debug: true,

                // The event handler functions are defined in handlers.js
                file_queued_handler : fileQueued,
                file_queue_error_handler : fileQueueError,
                file_dialog_complete_handler : fileDialogComplete,
                upload_start_handler : uploadStart,
                upload_progress_handler : uploadProgress,
                upload_error_handler : uploadError,
                upload_success_handler : uploadSuccess,
                upload_complete_handler : uploadComplete,
                queue_complete_handler : queueComplete    // Queue plugin event
            });

            //swfu = new SWFUpload(settings);
         };
    
</head>

.
.
.
<div id="content">
    &lt;form id="form1" action="&lt;?=base_url();?&gt;index.php/projects/miniuploadx" method="post" enctype="multipart/form-data"&gt;
            <fieldset class="flash" id="fsUploadProgress">
            <legend>Upload Queue</legend>
            </fieldset>
        <div id="divStatus">0 Files Uploaded</div>
            <div>
                &lt;input type="button" value="Upload file" onclick="swfu.selectFiles()" style="font-size: 8pt;" /&gt;
                &lt;input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="font-size: 8pt;" /&gt;
            </div>

    &lt;/form&gt;
</div>
controller projects.php
Code:
function miniuploadx(){
        
     $config['upload_path'] = 'upload/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '10000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);

        //load view

    }
function dominiuploadx(){
        log_message('debug', explode(',' , $_POST) );


        $this->upload->do_upload('Filedata');
        $res = $this->upload->data();

        echo $res['file_name'];
}

swfdebug

Code:
SWF DEBUG: SWFUpload Init Complete
SWF DEBUG:
SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Build Number:           SWFUPLOAD 2.1.0 FP9 2008-05-12
SWF DEBUG: movieName:              SWFUpload_0
SWF DEBUG: Upload URL:             http://www.domain.tld/index.php/projects/dominiuploadx
SWF DEBUG: File Types String:      *.*
SWF DEBUG: Parsed File Types:      
SWF DEBUG: File Types Description: All Files (*.*)
SWF DEBUG: File Size Limit:        67108864 bytes
SWF DEBUG: File Upload Limit:      100
SWF DEBUG: File Queue Limit:       100
SWF DEBUG: Post Params:
SWF DEBUG:                         PHPSESSID=85ab2946a8fb7c92b125fe85400c44de
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG:
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.*
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: Global Post Item: PHPSESSID=85ab2946a8fb7c92b125fe85400c44de
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload.  Starting upload to http://www.domain.tld/index.php/projects/dominiuploadx for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 32768. Total: 71189
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 65536. Total: 71189
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 71189. Total: 71189
SWF DEBUG: Event: uploadSuccess: File ID: SWFUpload_0_0 Data:
HTML FROM LOGIN SCREEN
.
.
.
.
.

Any suggestion? what did i do wrong?
#14

[eluser]mmorgensen[/eluser]
Can you let us know what you mean by session problems?

Just adding the "PHPSESSID" to your SWFUploader does not really do anything, you need to build in logic on the backend to map that session id back to a known user....

for example...


Bob has the session of 123ABC
Bob uses SWFUpload to send a file, we include PHPSESSID=123ABC
SWFUpload posts the form and uploads the data, but because of the way flash handles the upload, the flash app part gets it's own session id of XYZ789.

When the form is submitted, the controller processing the form needs to pull the $_POST['PHPSESSID'] value of ABC123 and map it back to the user Bob. It can pretty much ignore the session id of XYZ789, as it's not needed.

How you get your application to map the session id back to Bob is the tricky part. Smile

For me, I don't actually use the session id; gave up on this. I assign each user a unique 64bit APIKey that they use for uploading. If this value matches, they are golden to upload files. However, if someone else gets a hold of a person's APIKey, then they can upload file to the users account. I give the users a way to change their API key at will too. Smile I'm dealing with a low security app, your mileage may vary depending on your requirements.
Code:
if( isset($_POST['APIKEY']) ){
     $getuser = "SELECT username, user_id, user_bucket, site_apikey
                 FROM ht_users
                 WHERE site_apikey = ? ";
     $query = $this->db->query($getuser, array($_POST['APIKEY']) );
     $userdata = $query->row_array();
}

Hope this helps
#15

[eluser]taewoo[/eluser]
@w3builder: Where are these functions declared?

swfUploadLoaded
fileQueued
fileQueueError
fileDialogComplete


Can anyone show me what these event handlers are supposed to do?
#16

[eluser]Typeslowly[/eluser]
Please ignore this post, I just discovered encrypt_name which works great!



Great example and is working fine.

I would like to save the uploaded file with a unique name. I can create the unique name with my own function but am struggling to assign this unique name to the file when it is uploaded.

Any suggestions greatly appreciated.

Thanks.


[quote author="Merolen" date="1204688480"]I've been trying to make SWFUpload to work with CI as well. After using this post and the wiki entry as a startingpoing I've got a working sample.

Here is my experience:

I've used both the handler.js, swfupload.js, main.css and the images from the demo. I've used absolute path, guess it works fine with relative as well. This is put within the &lt;head&gt; tags:
Code:
&lt;link rel="stylesheet" type="text/css" href="/absolute/path/to/css/default.css" /&gt;
&lt;script type="text/javascript" src="/absolute/path/to/handlers.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="/absolute/path/to/swfupload.js"&gt;&lt;/script&gt;

Then the SWFUpload initialization, this is copied from the demo. Note that this has to be within the &lt;head&gt; tags. Here I've given the URL, the demo uses relative path. But this works for me:
Code:
var swfu;
        window.onload = function () {
            swfu = new SWFUpload({
                // Backend Settings
                upload_url : "http://www.mysite.com/upload/do_upload",
                flash_url : "http://www.mysite.com/path/to/swfupload_f9.swf",
                
                // Don't think this is needed
                post_params: {"PHPSESSID": "&lt;?php echo session_id(); ?&gt;"},

                // File Upload Settings
                file_size_limit : "2048",    // 2MB
                file_types : "*.jpg",
                file_types_description : "JPG Images",
                file_upload_limit : "0",

                // Event Handler Settings - these functions as defined in Handlers.js
                //  The handlers are not part of SWFUpload but are part of my website and control how
                //  my website reacts to the SWFUpload events.
                file_queue_error_handler : fileQueueError,
                file_dialog_complete_handler : fileDialogComplete,
                upload_progress_handler : uploadProgress,
                upload_error_handler : uploadError,
                upload_success_handler : uploadSuccess,
                upload_complete_handler : uploadComplete,

                custom_settings : {
                    upload_target : "divFileProgressContainer"
                },
                
                // Debug Settings
                debug: false
            });
        }

Now the code in the controller. My class is called upload and the function is called do_upload, the function must not be confused with CI's own do_upload function which is used inside our own do_upload. The most important thing to notice here is the echo at the bottom. If nothing is echoed the upload will just hang. The echo is the way to send information to the handler.js. Here the filename is echoed so that the image can be shown when the upload is finished.

Code:
class Upload extends Controller {
    
    function Upload() {
        parent::Controller();
        $config['upload_path'] = './relative/to/root/upload';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '1000';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
    }
    
    function do_upload() {
        $this->upload->do_upload('Filedata');
        $res = $this->upload->data();

        echo $res['file_name'];
    }
}

And now to the view file which will show the upload button
Code:
<div style="margin: 0px 10px;">
    &lt;form&gt;
        &lt;button id="btnBrowse" type="button" style="padding: 5px;" onclick="swfu.selectFiles(); this.blur();"&gt;
            Select Images <span style="font-size: 7pt;"></span></button>
    &lt;/form&gt;
    </div>
    <div id="divFileProgressContainer" style="height: 75px;"></div>
    <div id="thumbnails"></div>
</div>

So the handler.js. You want to have a look at the function uploadSuccess where the AddImage function is called. Change the 'thumbnail.php?id=' + server_data to '/path/to/your/pic/' + server_data. Server_data is what we echoed in the do_upload function. Also just scroll through the file to change the text messages and gif urls.
For debugging I echoed information from $this->upload->data(); and wrote alert(server_data) before the AddImage function is called in uploadSuccess.

Remember to fix the mime-type in system/application/config/mimes.php and add 'application/octet-stream'. Some say that this may be a security risk, I don't know, but it has to be done for it to work.

Code:
'jpeg'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpe'    =>    array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'png'    =>    array('image/png',  'image/x-png', 'application/octet-stream'),

I hope this helps.[/quote]
#17

[eluser]Sixer[/eluser]
If this helps anyone (I'm still working on fixing my problem):

SWFUpload, at least here, seems to insist on putting the post_params also into a GET, appended to the URL you're specifying.

For example: http://your.site/script/foo/?PHPSESSID=f...f562r3f67e

You can see this in your apache2 access_log if you have access to it.

This ?PHPSESSID= of course is being sanitized by CI and therefore throws back a big middle finger to SWFUpload, even though you see the whole file being posted.
#18

[eluser]Sixer[/eluser]
Seems like you _have_ to use the Flash 9 version of the swf.

That way, you can set use_query_string:false.

That way, SWFUpload doesn't set GET strings at the end of the URL that cause CI to refuse the request.

Having said that, CI's session library and any Flash frontend to uploads are simply not meant to be together. It's based on cookies, which is discarded by Flash as an intermediary.

You can go back to PHP's own session system and still use the same code you have in CI now, if you replace its session library by the one documented here: http://codeigniter.com/wiki/Native_session/

If you want to keep CI intact however, work around it instead, like other users have. By passing some kind of key to SWFUpload that you keep in your database for each of your users. Then look for the right user based on that key.
#19

[eluser]outrage[/eluser]
I've just found this thread after having session problems myself with several flash upload components.

For anyone else having the same problems, you may be able to get around it by setting
$config['sess_match_useragent'] = FALSE;
in your config file.

You see, the CI session manager is getting a different user agent string from your flash component and destroying the session.
#20

[eluser]Tobz[/eluser]
aha, good thinking batman - will do.




Theme © iAndrew 2016 - Forum software by © MyBB