Welcome Guest, Not a member yet? Register   Sign In
Getting uploadify to work
#31

[eluser]pickupman[/eluser]
Thanks everybody for all of the input on this. I finally got it working as well. I tried all sorts of ways to make the script post to the CI controller. Nothing was working. I was reading another's post on the uploadify forum about the same issues with CI. The trick lies in the onComplete callback in uploadify. This is how you can process through CI.

I modified another user's code for the uploadify/upload.php. The set_filename function was not working for non-random filenames. Recopied CI's functions back in.
/uploadify/upload.php
Code:
<?php
/*
*    Functions taken from CI_Upload Class
*
*/
    
    function set_filename($path, $filename, $file_ext, $encrypt_name = FALSE)
    {
        if ($encrypt_name == TRUE)
        {        
            mt_srand();
            $filename = md5(uniqid(mt_rand())).$file_ext;    
        }
    
        if ( ! file_exists($path.$filename))
        {
            return $filename;
        }
    
        $filename = str_replace($file_ext, '', $filename);
        
        $new_filename = '';
        for ($i = 1; $i < 100; $i++)
        {            
            if ( ! file_exists($path.$filename.$i.$file_ext))
            {
                $new_filename = $filename.$i.$file_ext;
                break;
            }
        }

        if ($new_filename == '')
        {
            return FALSE;
        }
        else
        {
            return $new_filename;
        }
    }
    
    function prep_filename($filename) {
       if (strpos($filename, '.') === FALSE) {
          return $filename;
       }
       $parts = explode('.', $filename);
       $ext = array_pop($parts);
       $filename    = array_shift($parts);
       foreach ($parts as $part) {
          $filename .= '.'.$part;
       }
       $filename .= '.'.$ext;
       return $filename;
    }
    
    function get_extension($filename) {
       $x = explode('.', $filename);
       return '.'.end($x);
    }


// Uploadify v1.6.2
// Copyright (C) 2009 by Ronnie Garcia
// Co-developed by Travis Nickels
if (!empty($_FILES)) {
    $path = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
   //$client_id = $_GET['client_id'];
   $file_temp = $_FILES['Filedata']['tmp_name'];
   $file_name = prep_filename($_FILES['Filedata']['name']);
   $file_ext = get_extension($_FILES['Filedata']['name']);
   $real_name = $file_name;
   $newf_name = set_filename($path, $file_name, $file_ext);
   $file_size = round($_FILES['Filedata']['size']/1024, 2);
   $file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['Filedata']['type']);
   $file_type = strtolower($file_type);
   $targetFile =  str_replace('//','/',$path) . $newf_name;
   move_uploaded_file($file_temp,$targetFile);

   $filearray = array();
   $filearray['file_name'] = $newf_name;
   $filearray['real_name'] = $real_name;
   $filearray['file_ext'] = $file_ext;
   $filearray['file_size'] = $file_size;
   $filearray['file_path'] = $targetFile;
   //$filearray['client_id'] = $client_id;

   $json_array = json_encode($filearray);
   echo $json_array;
}else{
    echo "1";    
}

I have a controller named Upload. I have three functions index(display form), do_upload(non-JS upload), uploadify(process callback from onComplete).

Here is my jQuery in controller Upload in my function index
Code:
$data['custom_jquery'] = '$("#fileData").fileUpload ({
            \'uploader\'  : \''.base_url().'js/jquery.uploadify-v1.6.2/uploader.swf\',
            \'script\'    : \'/js/jquery.uploadify-v1.6.2/upload.php\',
            \'cancelImg\' : \''.base_url().'js/jquery.uploadify-v1.6.2/cancel.png\',
            \'auto\'      : false,
            \'multi\'     : true,
            \'fileDesc\'  : \'Select an jpg, gif, pdf, png, or tiff\',
            \'fileExt\'   : \'*.jpg;*.jpeg;*.gif;*.pdf;*.png;*.tif\',
            \'fileDataName\' : \'Filedata\',
            \'scriptAccess\' : \'always\',
            \'onError\' : function (a, b, c, d) {
                         if (d.status == 404)
                            alert(\'Could not find upload script.\');
                         else if (d.type === "HTTP")
                            alert(\'error \'+d.type+": "+d.status);
                         else if (d.type ==="File Size")
                            alert(c.name+\' \'+d.type+\' Limit: \'+Math.round(d.sizeLimit/1024)+\'KB\');
                         else
                            alert(\'error \'+d.type+": "+d.text);
                        },
            \'onComplete\'   : function (event, queueID, fileObj, response, data) {
         $.post("'.site_url('upload/uploadify').'", { filearray : response },function(html){
                    $("#target").append(html);                                                                      
                });
         },
            \'onAllComplete\': function(event, data) {
         //alert("Uploading Complete!\\nTotal uploaded: "+data.filesUploaded+"\\nTotal errors: "+data.errors+"\\nClose this box to refresh the page and see your uploaded files.");
               },
            \'folder\'    : \'/uploads\'
            
        });';
I load jQuery in the controller, so I know what jQuery I am using for a certain page/function. The onComplete callback will POST the form data via upload.php and jQuery to /upload/uploadify.
#32

[eluser]pickupman[/eluser]
...Continued from above
This is where I can manipulate the file and add to DB or do something else fun. I have it echoing back a form to add a description.
In my controller Upload function uploadify
Code:
function uploadify()
    {
        $file = $this->input->post('filearray');
        $json = json_decode($file);
        
        $config['image_library'] = 'gd2';
        $config['source_image'] = './uploads/'.$json->{'file_name'};
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 75;
        $config['height'] = 50;
        
        $this->load->library('image_lib', $config); //Image Manipulation Library

        $this->image_lib->resize(); //Create thumbnail
        
        $thumb = str_replace($json->{'file_ext'},'',$json->{'file_name'});
        $thumb = $thumb."_thumb".$json->{'file_ext'};
        
        $this->load->library('table');
        
        $this->table->set_heading('Image','Enter Description','');
        
        $this->table->add_row('<img src="'.base_url().'uploads/'.$thumb.'" alt="" />','&lt;input type="text" name="gal" value="" /&gt;','<button type="text" value="Update">Update</button>');
        echo $this->table->generate();
    }
Here is my view 'upload/view.php' called in controller Upload function index
Code:
$this->load->view('upload/view',$data);
Code:
&lt;?php echo $this->load->view('header.php');?&gt;


    &lt;?php if(isset($error)) echo $error;?&gt;
    &lt;?=form_open_multipart('upload/do_upload');?&gt;
    
    &lt;input type="file" name="Filedata" id="fileData" value=""/&gt;
    
    <a href="javascr|pt:$('#fileData').fileUploadStart();">Upload Files</a><br />
    
    &lt;?=form_close();?&gt;
    
       <div id="target">
    
    </div>
    
&lt;?php echo $this->load->view('footer.php');
#33

[eluser]jaargo[/eluser]
I finally got it to work guys!

Really appreciate the help! thx once again! =)
#34

[eluser]Caelis[/eluser]
Hi!

I've managed to get Uploadify integrated and working within my little CMS system
that I have built for a basketball site thanks to some of the hints and tips by merqlove.

I might post my models, views and controllers here in a not to distant future in the hopes it helps others to integrate Uploadify in their own applications.
Not saying my solutions is 100% bulletproof (just discovered some security issues but I'm working on that ;-) ), but it works as it should Big Grin

It's just too bad that the second release of Uploadify is taking so long, since that would have the possibility to use it in an environment with POST natively.

All in all, I'm happy with the current results Smile
Just wanted to let you guys know!
#35

[eluser]lerva[/eluser]
Uploadify 2.0.0 is just been released. I tried it quickly (it supports POST and giving name of your files array in the upload server script, but still no luck. I think it is because of the pretty urls (same problems that before).

Anyone else tried this out yet?

Uploadify download & documentation
#36

[eluser]Caelis[/eluser]
I might try it out in a new application (based on my original basketball site application) that i'll be building in the next weeks.

I'll let you know my findings.
#37

[eluser]pickupman[/eluser]
Getting this to work has saved alot of time on a script I was using to import CSV files. Uploadify plus using "LOAD DATA LOCAL INFILE" has saved my day. I will try also testing on the new 2.0 script. It would nice to be able to use CI's built in functions for controlling the uploads.
#38

[eluser]chmod[/eluser]
good work. Can you share your code for me ? Would you please send me your controller/view as a zip file?
my email is [email protected].
thanks for you VERY MUCH!!!
#39

[eluser]t0psub[/eluser]
[quote author="merqlove" date="1247097939"]Hi guys!

My solution is:

Replace code in the .fla file at line 349, between:

Code:
if (param.script.substr(0,1) != '/') param.script = param.pagepath + param.script;
REPLACE
file.upload(scriptURL, param.fileDataName);

REPLACE

Code:
var scriptURL:URLRequest = new URLRequest(param.script);
scriptURL.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.folder = getFolderPath();
variables.scriptdata = param.scriptData;
scriptURL.contentType = 'multipart/form-data';
scriptURL.data = variables;

RESULT:

Code:
if (param.script.substr(0,1) != '/') param.script = param.pagepath + param.script;
var scriptURL:URLRequest = new URLRequest(param.script);
scriptURL.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.folder = getFolderPath();
variables.scriptdata = param.scriptData;
scriptURL.contentType = 'multipart/form-data';
scriptURL.data = variables;
file.upload(scriptURL, param.fileDataName);

Now i using CI standard Upload library with disabled file_type checking.
Uploading is true work. I saw uploaded files.

UPD.
Growl too work. Just cleaned 'path' var from Growl onComplete.
Because i have 1 folder with subfolders by file types.

UPD.

I have changed Upload class for check via extensions.
Because server return type of any file as "application/octet-stream" because we are using flash for upload.

Cheers, Alex[/quote]

I used your swf file but when i select an image it doesn't display anything in the queue like the default file does, Thoughts?

EDIT: i was using the newest version which was released after you wrote this.
I converted back to the older uploadify and it says the file is up loaded but its not.

I'm am using your custom .swf file and posting to my contorler "file/upload" and it seems $_FILES is empty so it can't upload.. Am i trying to upload these images wrong or something?

Any thoughts?
#40

[eluser]t0psub[/eluser]
Hey,

It seems that when my form is posting to CI its looking all the session i've defined in CI. Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB