⚠ 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

Why does image upload fails?



larasmith
  • profile picture
  • Member

Posted 09 June 2017 - 05:49 AM

I followed the API and function guide for uploading from here:

https://www.grocerycrud.com/enterprise/api-and-function-list/setFieldUpload

		$crud->setFieldUpload('u_Image','assets/images/uploads','assets/images/uploads');
		$crud->setFieldUpload('u_Sig','assets/images/uploads','assets/images/uploads');

I used an old table with actual correct file path and images to test.

The image appears as a preview. But uploading a new photo

fails and an error is displayed on the console as shown

in the image below:

 

image.png


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

Posted 10 June 2017 - 21:00 PM

I had a similar situation with Laravel and it seems that the CSRF protection is causing the issue.

 

This is something that I am working on to solve it as it seems that only the upload functionality has this issue. Can you please disable the CSRF protection (from application/config/config.php -> $config['csrf_protection'] = FALSE;) to see if this will work for you? If it will work then at least I will have more clue about what the issue is.

 

Thanks

Johnny


larasmith
  • profile picture
  • Member

Posted 11 June 2017 - 02:23 AM



I had a similar situation with Laravel and it seems that the CSRF protection is causing the issue.

 

This is something that I am working on to solve it as it seems that only the upload functionality has this issue. Can you please disable the CSRF protection (from application/config/config.php -> $config['csrf_protection'] = FALSE;) to see if this will work for you? If it will work then at least I will have more clue about what the issue is.

 

Thanks

Johnny

 

Hello Sir Johny! Thank you for answering my question.

By default the value of $config['csrf_protection'] in the config file is false. 


larasmith
  • profile picture
  • Member

Posted 13 June 2017 - 01:12 AM

Thank you for helping me out.

 

Do we have other solutions to try?


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

Posted 14 June 2017 - 19:49 PM

Hello Lara,

 

I am copying an email that I did get from another user that did found the solution and it was only for windows that is using xampp:

 

Problem fixed. It's not a bug. I try to trace all error caused and found error undefined function finfo libraries\codeguy\upload\src\Upload\File.php line 203. Then I activate php_fileinfo extension in php.ini configuration and now file upload running well. Maybe you should add in documentation how to fix file upload problem since xampp installation doesn't have php_fileinfo activated by defaut. Thanks John :)

 

I hope the above ^ will help.

 

Thanks
Johnny


larasmith
  • profile picture
  • Member

Posted 15 June 2017 - 06:30 AM

Hello Lara,

 

I am copying an email that I did get from another user that did found the solution and it was only for windows that is using xampp:

 

 

I hope the above ^ will help.

 

Thanks
Johnny

 

Hello Sir Johnny!

 

Unfortunately it still doesn't work for me.  :(

Same error occurs.  :(

 

I am now trying to setup a manual installation instead of XAMPP.

I'll let you know what happens next.

 

Thanks!


larasmith
  • profile picture
  • Member

Posted 19 June 2017 - 06:07 AM

Hello Sir Johny,

 

I was finally able to do a manual setup of Apache, PHP and MySQL and run my program on it.

The same problem occurs with the upload.

 

Here is the screenshot of the details:

image.png

 

What solution do you suggest? 

 

Thanks!


larasmith
  • profile picture
  • Member

Posted 21 June 2017 - 05:35 AM

Hello again!

 

I noticed that the upload works when the supplied path of directory is:

(This is on the sample development system I sent you earlier)

        './assets/images/uploads'

but once I used:

(This is the actual system that I am developing)

       '../assets/images/uploads'

 

I need the second one because it is the actual location of the photo.

How come that it can display the image properly but fails during the upload?

By the way the CRUD that I am working on is inside an iframe.

Would that be an issue?

 

Thanks!


nunenthal
  • profile picture
  • Member

Posted 03 March 2019 - 18:23 PM

Work for me width :

$crud->setFieldUpload('fichier', './assets/logos','../assets/logos');

 

And in my resize function I must use this :

 $crud->callbackAfterUpload(function ($data = null) {   
$file_uploaded =  $_SERVER['DOCUMENT_ROOT'].'/assets/logos/' . $data->filename;

$size=getimagesize($file_uploaded);

.....

 

 

It's very strange, but this work.