Jump to content


File Upload Issue


  • Please log in to reply
18 replies to this topic

#1 cboyd

cboyd

    Member

  • Members
  • PipPip
  • 12 posts

Posted 20 May 2012 - 07: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!

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,155 posts
  • LocationLondon

Posted 20 May 2012 - 07: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.
Posted Image

#3 cboyd

cboyd

    Member

  • Members
  • PipPip
  • 12 posts

Posted 20 May 2012 - 09: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!

#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,155 posts
  • LocationLondon

Posted 20 May 2012 - 10: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.
Posted Image

#5 cboyd

cboyd

    Member

  • Members
  • PipPip
  • 12 posts

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

#6 cboyd

cboyd

    Member

  • Members
  • PipPip
  • 12 posts

Posted 21 May 2012 - 10:31 AM

And here is the code generated for the upload field:

<div class='form-field-box odd' id="component_image_field_box">
<div class='form-display-as-box' id="component_image_display_as_box">
Component image :
</div>
<div class='form-input-box' id="component_image_input_box">
<span class="fileinput-button qq-upload-button" id="upload-button-4fba1810cd070" style="">
<span>Upload a file</span>
<input type="file" name="s90ba65e8" class="gc-file-upload" rel="http://www.xxx.com/i...omponent_image" id="4fba1810cd070">
<input class="hidden-upload-input" type="hidden" name="component_image" value="" rel="s90ba65e8" />
</span><div id='uploader_4fba1810cd070' rel='4fba1810cd070' class='grocery-crud-uploader' style=''></div><div id='success_4fba1810cd070' class='upload-success-url' style='display:none; padding-top:7px;'> <a href='http://www.xxx.com/a.../1/component/1/' class='open-file' target='_blank' id='file_4fba1810cd070'></a> &nbsp;&nbsp;<a href='javascript:void(0)' id='delete_4fba1810cd070' class='delete-anchor'><img src='/assets/grocery_crud/themes/flexigrid/css/images/close.png' title='delete image' border='[url=""]0[/url]' /></a> </div><div style='[url=""]clear:both[/url]'></div><div id='[url=""]loading-4fba1810cd070[/url]' style='[url=""]display:none[/url]'><span id='[url=""]upload-state-message-4fba1810cd070[/url]'></span> <span class='[url=""]qq-upload-spinner[/url]'></span> <span id='[url=""]progress-4fba1810cd070[/url]'></span></div><div style='[url=""]display:none[/url]'><a href='[url="view-source:http://catalog.oxfordeltresources.com/index.php/component/cat_component/upload_file/component_image"]http://[/url][url="view-source:http://catalog.oxfordeltresources.com/index.php/component/cat_component/upload_file/component_image"]www.xxx[/url][url="view-source:http://catalog.oxfordeltresources.com/index.php/component/cat_component/upload_file/component_image"].com/index.php/component/cat_component/upload_file/component_image[/url]' id='[url=""]url_4fba1810cd070[/url]'></a></div><div style='[url=""]display:none[/url]'><a href='[url="view-source:http://catalog.oxfordeltresources.com/index.php/component/cat_component/delete_file/component_image"]http://[/url][url="view-source:http://catalog.oxfordeltresources.com/index.php/component/cat_component/delete_file/component_image"]www.xxx[/url][url="view-source:http://catalog.oxfordeltresources.com/index.php/component/cat_component/delete_file/component_image"].com/index.php/component/cat_component/delete_file/component_image[/url]' id='[url=""]delete_url_4fba1810cd070[/url]' rel='' ></a></div> </div>
<div class='[url=""]clear[/url]'></div>
</div>
Thanks!

#7 cboyd

cboyd

    Member

  • Members
  • PipPip
  • 12 posts

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? ;)

#8 cboyd

cboyd

    Member

  • Members
  • PipPip
  • 12 posts

Posted 21 May 2012 - 02: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!

#9 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,155 posts
  • LocationLondon

Posted 21 May 2012 - 06:57 PM

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

#10 crina

crina

    Member

  • Members
  • PipPip
  • 17 posts

Posted 24 May 2012 - 11:06 AM

Hi,

I'm also facing some problems with the uploader ... sometimes it works perfectly, sometimes it doesen't work at all ... 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:error js.png

#11 ricocsharp

ricocsharp

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 04 June 2012 - 01: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.

#12 rhouzvecxs

rhouzvecxs

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 05 June 2012 - 12:52 PM

Hi everyone,

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

#13 sachin vairagi

sachin vairagi

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

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. 



#14 clustersblue

clustersblue

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

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



#15 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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.



#16 clustersblue

clustersblue

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

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?

#17 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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:)



#18 clustersblue

clustersblue

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

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]) )
		{
...


#19 Sonali Patel

Sonali Patel

    Newbie

  • Members
  • Pip
  • 1 posts

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users