swfupload problems! - El Forum - 09-10-2008
[eluser]MMCCQQ[/eluser]
hi!
i can't upload a file with swfupload
this is my code: i using SWFupload Sample.
Code: [removed]
var swfu;
window.onload = function() {
// Max settings
swfu = new SWFUpload({
upload_script : "http://localhost/S5/index.php/users/subiendo_fotos",
post_params: {"PHPSESSID": "cf7mgr76aqh4j9ndgue9nd7kc4"},
target : "SWFUploadTarget",
flash_path : "<?=base_url()?>swfupload/swfupload_f9.swf",
allowed_filesize : 30720, // 30 MB
allowed_filetypes : "*.*",
allowed_filetypes_description : "All files...",
browse_link_innerhtml : "Elegir fotos",
upload_link_innerhtml : "Subir fotos",
browse_link_class : "swfuploadbtn browsebtn",
upload_link_class : "swfuploadbtn uploadbtn",
upload_file_queued_callback : fileQueued,
upload_file_start_callback : uploadFileStart,
upload_progress_callback : uploadProgress,
upload_file_complete_callback : uploadFileComplete,
upload_file_cancel_callback : uploadFileCancelled,
upload_queue_complete_callback : uploadQueueComplete,
upload_file_error_callback : uploadError,
upload_file_cancel_callback : uploadFileCancelled,
debug : false
});
};
[removed]
<div id="titl_msg">Subir fotos</div>
<div id="form-box" style="border-color:#EBF2D6;">
<div id="SWFUploadTarget">
<form action="<?=site_url();?>/users/subiendo_fotos" method="post" enctype="multipart/form-data">
<input type="file" name="Filedata" id="Filedata" />
<input type="submit" value="upload test" />
</form>
</div>
<h4 id="queueinfo">Queue is empty</h4>
<div id="fsUploadProgress" style="height: 75px;"></div>
<div id="SWFUploadFileListingFiles"></div>
<br class="clr" />
<a class="swfuploadbtn" id="cancelqueuebtn" href="[removed]cancelQueue();">Cancel queue</a> </div>
</div>
this is the controller
Code: function Subiendo_fotos(){
$this->load->library('upload');
$config['upload_path'] = 'c://AppServ/www/S5/images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->upload->initialize($config);
$this->upload->do_upload('Filedata');
echo $this->upload->display_errors();
}
i dont know what happed because dont display any errors..i tested without swfupload and worked pretty good.
swfupload problems! - El Forum - 09-10-2008
[eluser]mglinski[/eluser]
This has been discussed many times before. Please try searching, as you may find your answer much more quickly.
-Matt
swfupload problems! - El Forum - 09-10-2008
[eluser]MMCCQQ[/eluser]
well,,well..i added MY_Upload.php..and dont work...
who made swfupload work?
HELP!
swfupload problems! - El Forum - 09-11-2008
[eluser]Chris Newton[/eluser]
I gave up on swfupload. I MUCH prefer the following:
http://don.citarella.net/index.php/actionscript-examples/flash-file-uploader/
I found it to be simpler & more reliable on all counts. It can't be styled with CSS, which is (as far as I'm concerned) is no big deal anyway. I created a CI specific version of that where all of the error reporting is handled by javascript on page, so basically the flash just needs styling changes from site to site. Unfortunately, I don't have that in a format that's easy to digest (yet) and I'm at the tail end of the gigantic project that required me to figure this stuff out in the first place so I have little time to spare.
That being said. Here's what I have for swfupload (which btw, does not work on MOSSO host, but works just fine on Dreamhost, and several other hosts) This was some dev code, so there's some dumb stuff still in here.
Controller Code
Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Create extends Controller
{
function Create()
{
parent::Controller();
// Keeping the image sizing consistent
$this->image_config_width = 458;
$this->image_config_height = 649;
$this->image_preview_width = 711;
$this->image_preview_height = 1008;
}
/**
* Image uploader
*
* Aids in the uploading & storage of images for
* later manipulation. If used with SWFUpload the
* fieldname must be Filedata
*
* @param string $fieldname ID of the input field uploading image/file. MUST BE 'Filedata' to work with SWFUpload
* @param bool $flash optional, if FALSE, data will be returned, rather than echo'd.
* @access public
* @return array or echo
*/
function upload_image($fieldname='Filedata', $flash=TRUE)
{
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
}
// The upload function has a common configuration file with filesize, min, max settings
$this->config->load('upload');
$this->load->library('upload');
$this->load->library('phpsession');
$this->load->helper(array('url'));
// Starting a session to find the ID of the page that uploaded the file
$session_id = session_id();
// FAILED UPLOAD
if (!$this->upload->do_upload($fieldname))
{
$data['result'] = 'failure';
// must start with 'error'for the javascript error reporting to work correctly.
$data['errors'] = 'error|';
$data['errors'] .= $this->upload->display_errors('', '|');
if ($flash)
{
echo $data['errors'];
}
}
// SUCCESSFUL UPLOAD
else
{
$upload_data = $this->upload->data();
$data['result'] = 'success';
$data['file_name'] = $upload_data['file_name'];
$data['file_path'] = $upload_data['file_path'];
if ($flash)
{
// flash must receive a message to achieve 'success'. Javascript handlers can be used to override this data's output
echo $data['file_name'];
}
else
{
echo "error|copying the uploaded file failed";
}
// saving the filename to session so that the filename can be picked up by the next script
}
if (!$flash)
{
return $data;
}
else
{
return 'A flash error has occurred #1002';
}
}
}
swfupload problems! - El Forum - 09-11-2008
[eluser]Chris Newton[/eluser]
Javascript and CSS.
Code: <link href="'.base_url().'css/swfupload.css" rel="stylesheet" type="text/css" />
[removed][removed]
[removed][removed]
[removed][removed]
[removed][removed]
[removed][removed]
[removed]
var swfu;
window.onload = function() {
var settings = {
flash_url : "'.base_url().'swfupload/swfupload_f9.swf",
upload_url: "'.$form_action.'",
post_params: {"PHPSESSID" : "'.$session_id.'"},
file_size_limit : "'.$file_size_limit.'",
file_types : "'.$file_types.'",
file_types_description : "'.$file_types_description.'",
file_upload_limit : '.$file_upload_limit.',
file_queue_limit : '.$file_queue_limit.',
custom_settings : '.$custom_settings.',
debug: '.$debug.',
file_queued_handler : '.$file_queued_handler.',
file_queue_error_handler : '.$file_queue_error_handler.',
file_dialog_complete_handler : '.$file_dialog_complete_handler.',
upload_start_handler : '.$upload_start_handler.',
upload_progress_handler : '.$upload_progress_handler.',
upload_error_handler : '.$upload_error_handler.',
upload_success_handler : '.$upload_success_handler.',
upload_complete_handler : '.$upload_complete_handler.',
queue_complete_handler : '.$queue_complete_handler.'
};
swfu = new SWFUpload(settings);
};
[removed]
swfupload problems! - El Forum - 09-11-2008
[eluser]Chris Newton[/eluser]
Upload code
Code: <div id="upload_box">
<?php
echo form_open_multipart($form_action,$form_attributes);
echo '<div class="content">';
echo form_fieldset('upload progress',$fieldset);
echo nbs(1);
echo form_fieldset_close();
echo form_input($userfile);
echo form_input($cancel_button);
echo '<div id="divStatus">0 Files Uploaded</div>';
echo "</div>";
echo form_close();
echo br(3);
?>
</div>
swfupload problems! - El Forum - 09-11-2008
[eluser]Chris Newton[/eluser]
The trick as I recall with swfupload was that I had to 1. update the mimes config, 2. modify the UPLOADER library to actually USE those mimes to suit my purposes.
Anyway. I will never use swfupload again. It's junky. The one I mention above was very easy to integrate with CI, and it's also easy to integrate into other flash files. PLUS it doesn't take a ton of other javascripts to make it work. It's much more compact than swfuplod.
Also, if you're developing on a Windows box... there may be some issues with using swfupload based on the way upload reporting is handled on a window's machine. I'm not sure if the other file uploader has the same problem or not.
swfupload problems! - El Forum - 09-11-2008
[eluser]mglinski[/eluser]
I was just pointing out that SWFUpload does work on CI, and some searching will get the problem solved. I had no trouble integrating SWFUpload into a few major projects of mine, as long as you account for its (relatively few) quirks.
-Matt
swfupload problems! - El Forum - 09-11-2008
[eluser]gRoberts[/eluser]
The only issue I had with SWFUpload was the mime type. I then used the getimagesize function which got the mime type and set the $_FILES mime to the correct mime type before calling CI's upload.
swfupload problems! - El Forum - 09-11-2008
[eluser]Chris Newton[/eluser]
It definitely works. I have it working in a few places. I don't like it though, and find the other easier. gRoberts is right, the place I had the problem was with the mime type as well, which is why I ended up doing the my_upload bit. It seems like a recent release of code igniter reversed what Mr. Jones said here (in that the mime config file is respected now.) I could be totally wrong on that last bit, and I haven't tested it.
|