⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

File Upload Issue



cboyd
  • profile picture
  • Member

Posted 20 May 2012 - 19:09 PM

I am having a problem with the file upload capability. I have successfully implemented file uploads on one form on my site without any problem. However I am getting an error when I have tried to implement it on a second form.

I have defined the file upload directory ('assets/uploads/collection/1/component/1') and verified that it is writable (perms 777). The file browser works and the progress bar gets to about 96% before it errors. I have determined that the 'send' state of the 'fileupload' function is returning true. The error is being raised in the "done" state in jquery.fileupload.config.js. Clearly data.result.success is returning false, but I can't figure out why.

Any anyone shed any light on what the cause of the error might be?

Many thanks!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 20 May 2012 - 19:29 PM

The 96% means that all the data are sent to the server and the uploader just wait for a response from the PHP to say a DONE or something. So it is probably not a javascript issue but probably a PHP issue. Do you have any error message? Can you please check your firebug about a response? Also check the limitation of your php.ini max_upload_size or something like that, pehaps the php.ini stops the process without any error. Also can you tell me if it's on live server or it is at your local machine? Also it is good to know: OS, PHP version and grocery CRUD version.

It really can be anything so if you are more specific perhaps we can solve the problem.

cboyd
  • profile picture
  • Member

Posted 20 May 2012 - 21:12 PM

I am getting the "An error has occurred on uploading." error

The response variables at the time appear to be as follows:


typeof data.result.success=boolean
data.result.success=false
data.errorThrown=undefined
data.result.message=undefined
data.textStatus=success

OS: Linux whub28.webhostinghub.com 2.6.18-274.12.1.el5 #1 SMP Tue Nov 29 13:37:46 EST 2011 x86_64
PHP version 5.3.10
GroceryCRUD ver: 1.2
upload_max_filesize: 128M (my test file is only 858 KB)

Thanks for your help, web-johnny!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 20 May 2012 - 22:10 PM

Ok so you don't have any error. You have to debug it.

Go to application/libraries/grocery_crud.php

line 1143 and change the:


protected function upload_file($state_info)
{
if(isset($this->upload_fields[$state_info->field_name]) )
{

...


to:


protected function upload_file($state_info)
{
if(isset($this->upload_fields[$state_info->field_name]) )
{
echo "The problem is more complicated than I thought!";
}
else
{
echo "The problem is probably simple!<br/>";
echo $state_info->field_name."<br/>";
echo print_r($this->upload_fields,true);
}

die();

if(isset($this->upload_fields[$state_info->field_name]) )
{
...


So there you will actual see what the problem is at your firebug response:

If you have the message "The problem is more complicated than I thought!" so this means that there is something with the server that I can't help you with this as it could be anything. You have to go line by line from the line 1143 and debug it with simple messages and see the firebug response.

If the message is "The problem is probably simple!", so you probably just have a field name with a space or something. Make sure that you always have your field name with lowercase letters and not uppercase or space and always make sure that the second field doesn't begin or end with "/" (slash). If this doesn't work for you please add the function that you use here.

cboyd
  • profile picture
  • Member

Posted 21 May 2012 - 10:25 AM

Thanks for your assistance!

I get the following 'simple' response:
The problem is probably simple!<br/>component_image<br/>Array
(
)
I am not quite sure what you mean by the 'second field', but all of my field names are lower case and have dashes instead of spaces.

The function call is : $crud->set_field_upload('component_image','assets/uploads/collection/1/component/1');

cboyd
  • profile picture
  • Member

Posted 21 May 2012 - 10:31 AM

And here is the code generated for the upload field:

<div class='component_image_field_box">
<div class='component_image_display_as_box">
Component image :
</div>
<div class='component_image_input_box">
<span class="upload-button-4fba1810cd070" style="">
<span>Upload a file</span>
<input type="s90ba65e8" class="http://www.xxx.com/index.php/component/cat_component/upload_file/component_image" id="hidden-upload-input" type="component_image" value="" rel="uploader_4fba1810cd070' rel='grocery-crud-uploader' style=''></div><div id='upload-success-url' style='http://www.xxx.com/assets/uploads/collection/1/component/1/' class='_blank' id='javascript:void(0)' id='delete-anchor'><img src='/assets/grocery_crud/themes/flexigrid/css/images/close.png' title='0' /></a> </div><div style='loading-4fba1810cd070' style='upload-state-message-4fba1810cd070'></span> <span class='progress-4fba1810cd070'></span></div><div style='http://www.xxx.com/index.php/component/cat_component/upload_file/component_image' id='display:none'><a href='http://www.xxx.com/index.php/component/cat_component/delete_file/component_image' id='clear'></div>
</div>
Thanks!

cboyd
  • profile picture
  • Member

Posted 21 May 2012 - 12:08 PM

In an attempt to troubleshoot I have added these line as the first lines of the upload_file function:

print_r($this->upload_fields[$state_info->field_name]);
die();

For the page that is failing, I am getting the following response:

<p>Severity: Notice</p>
<p>Message: Undefined index: image</p>
<p>Filename: libraries/grocery_crud.php</p>
<p>Line Number: 1073</p>

If I print_r the $state_info, I only get:
stdClass Object
(
[field_name] => image
)

instead of the:

stdClass Object
(
[field_name] => image
[upload_path] => assets/uploads/collection/1
[encrypted_field_name] => s78805a22
)

I get on the page that successfully downloads.

Does that help? ;)

cboyd
  • profile picture
  • Member

Posted 21 May 2012 - 14:23 PM

I figured it out: I was conditionally setting the upload directory based on the state being 'add or 'edit' (which for some reason was not working), so the upload dir was not getting set. I removed the condition, and it works

Thanks, web-johnny!

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 21 May 2012 - 18:57 PM

I told you that: echo "The problem is probably simple!<br/>" hehehe :)

crina
  • profile picture
  • Member

Posted 24 May 2012 - 11:06 AM

Hi,

I'm also facing some problems with the uploader ...[color=#0000cd] sometimes it works perfectly, sometimes it doesen't work at all[/color] ... I'm tring to debug for two day now ... I have put the code you suggested

if(isset($this->upload_fields[$state_info->field_name]) )
{
echo "The problem is more complicated than I thought!";
}
else
{
echo "The problem is probably simple!<br/>";
echo $state_info->field_name."<br/>";
echo print_r($this->upload_fields,true);
}

die();



but ... it goes on this brach : "The problem is more complicated than I thought!"... :(
do you have some more suggestions why is this happening ?

And if I succed the upload, when I try to delete the image it gives me this in the Firebug console:[attachment=178:error js.png]

ricocsharp
  • profile picture
  • Member

Posted 04 June 2012 - 13:24 PM

I'm in the same situation I'm always receiving the "An error has occurred on uploading." message,

triyng to clarify the source I started testing my server settings so checked an old php project and uploading files functionallyty is working, so I think is a grocery crud library bug. is there any new on this?

I checked also the upload folder on my server and the file is there but with a diferent name (something-myfilename.jpg), so the upload process goes on but Ithink it fails trying to renaming back the file.

rhouzvecxs
  • profile picture
  • Member

Posted 05 June 2012 - 12:52 PM

Hi everyone,

Who knows how to view the image in the actual table?

sachin vairagi
  • profile picture
  • Member

Posted 09 February 2013 - 07:03 AM

hi,

 

i am facing problem with image uploading, sometimes image is uploading fine, but sometimes image is automatically resizing to 1x1.

i dont know what is the issue.

 

plesae help me,Thanks. 


clustersblue
  • profile picture
  • Member

Posted 27 November 2013 - 09:02 AM

Hi web-johnny,

 

When I tried your debugging code above, here is what I got:

The problem is probably simple!<br/><br/>Array
(
    [upload_file] => stdClass Object
        (
            [field_name] => upload_file
            [upload_path] => assets/uploads/files
            [encrypted_field_name] => sc310bc56
        )

)

I tried "assets/uploads/files" using CodeIgniter File Uploading class and work fine, I was able to upload the file, thus, seems I have no problem with my folder write access.  My "upload_file" field name is a varchar(50) in my DB.  I wonder if the file types matters?

 

I'm sharing you my code perhaps there is something that I missed there:

$crud = $this->grocery_crud;
                
                $crud->set_table('kaizen2')
                     ->set_subject('Kaizen')
                     ->set_relation('emp_number','users','username')
                     ->set_relation('waste_ID','waste','Waste')
                     ->set_relation('priority_ID','priority','priority')
                     ->set_relation_n_n('party_ID', 'interested_party', 'users', 'KaizenId', 'emp_number', 'username', null, array('users.active_ID'=>'1'))
                     ->where('kaizen2.emp_number',$this->session->userdata('emp_number'));

                $crud->display_as('KaizenId','ID')
                     ->display_as('ProposalTitle','Proposal Title')
                     ->display_as('emp_number','Proposed by')
                     ->display_as('waste_ID','Waste Category')
                     ->display_as('PotentialCostSavings','Potential Cost Saving')
                     ->display_as('SavingsSchedule','Saving Schedule')
                     ->display_as('CurrentMethod','Current Method')
                     ->display_as('ProposedMethod','Proposed Method')
                     ->display_as('priority_ID','Priority')
                     ->display_as('ImpDate','Implementation Date')
                     ->display_as('DateProposed','Date Proposed')
                     ->display_as('party_ID','Interested Party');

                $crud->columns('KaizenId','emp_number','ProposalTitle','Objectives','DateProposed','waste_ID');
                $crud->set_field_upload('upload_file','assets/uploads/files');
                $crud->add_fields('ProposalTitle','DateProposed','waste_ID','PotentialCostSavings','SavingsSchedule','Objectives','CurrentMethod','ProposedMethod','priority_ID','ImpDate','party_ID','upload_file');
                $crud->edit_fields('ProposalTitle','emp_number','DateProposed','waste_ID','PotentialCostSavings','SavingsSchedule','Objectives','CurrentMethod','ProposedMethod','priority_ID','ImpDate','party_ID','upload_file');
                $crud->required_fields('ProposalTitle','DateProposed','priority_ID','ImpDate');
                $crud->unset_delete();
                $crud->unset_texteditor('Objectives','CurrentMethod','ProposedMethod','Implementor','EvalComments','FirstComments','SecondComments','ProcessComments');
                $crud->callback_after_insert(array($this, '_kaizen_my_after_insert'));
                $crud->callback_edit_field('emp_number',array($this,'_edit_field_callback_kaizen_my'));
                
                $output = $crud->render();

                $this->load->view('main_view',$output);

Thanks,

Clustersblue


Amit Shah
  • profile picture
  • Member

Posted 28 November 2013 - 09:29 AM

Hi Clusterblue,

 

varchar(50) - can be 1 problem that it might truncate the file name that is being stored - if it goes beyond 50 chars.

When you upload using GC - it is an ajax upload and is uploaded immediately even before the form is submitted. It dose not create / update the entry into the system for that. Hence there is nothing to do with the size of the field name.

 

However as mentioned in last post of yours too.. yes that is quite possible that the issue can be of the file type that is being uploaded.


clustersblue
  • profile picture
  • Member

Posted 28 November 2013 - 12:35 PM

Hi Amit,

Actually the problem was not with my field. :) I just discovered today that if you notice the return value of web-johnny's debug script it missing something... There should be $state_info value between the two
... The value should be my field name string, in my case upload_file... I dont know the reason why it doesn't have value it could be in my code or not... So what i did was I just assigned my value directly to $state_info->file_name='upload_file'... Again Im not sure if what I did was advisable :) but it works!Have you encountered the same issue?

Amit Shah
  • profile picture
  • Member

Posted 28 November 2013 - 12:58 PM

Well frankly speaking i have not been encountering much of the upload issues .. as i manage the configurations (Code / serverside) well enough :D ... anyways... happy to see that you finally figured out a solution for yourself..

Infact i will recommend you paste out the code chunk of the solution you have had applied upon so that others may try to find if the solution actually worked out for them too or not. If so - it will be applied globally for the same.. else its applicable to you as it works for you.

 

Happy GCing:)


clustersblue
  • profile picture
  • Member

Posted 03 December 2013 - 07:17 AM

Here's what I did, I just appended the highlighted text below.

protected function upload_file($state_info)
	{
		$state_info->field_name='upload_file'; 
		if(isset($this->upload_fields[$state_info->field_name]) )
		{
...

Sonali Patel
  • profile picture
  • Member

Posted 27 March 2017 - 09:44 AM

Change

 

$options = array(
                    'upload_dir'         => $upload_info->upload_path.'/',
                    'param_name'        => $this->_unique_field_name($state_info->field_name),
                    'upload_url'        => base_url().$upload_info->upload_path.'/',
                    'accept_file_types' => $reg_exp,
                    'max_file_size'        => $max_file_size_bytes
                );

 

to

 

$options = array(
                    'upload_dir'         => '.'.$upload_info->upload_path.'/',
                    'param_name'        => $this->_unique_field_name($state_info->field_name),
                    'upload_url'        => base_url().$upload_info->upload_path.'/',
                    'accept_file_types' => $reg_exp,
                    'max_file_size'        => $max_file_size_bytes
                );

 

Consider highlighted area.

It works for me.