Support the ongoing development of Laravel.io →
Configuration Forms Packages
Last updated 2 years ago.
0

mmm, what returns Input::hasFile( 'image' ) ??

also, in your form setup, you need to specified the files attribute

{{ Form::open( [ 'url' => '...', 'method' => 'post', 'files' => true ] ) }}
Last updated 2 years ago.
0

Thanks arcollector for helping, but this brought me back to the same error after your modification. can you go through the whole code? thanks so much.

Last updated 2 years ago.
0

I found this error before. My PHP.ini setting were the culprit for this. Post_max_size or upload_max_size werent allowing the image to processed as the image file size broke these settings.

PS the return for hasFile() is a boolean not the file itself.

Last updated 2 years ago.
0

matthewburrow said:

I found this error before. My PHP.ini setting were the culprit for this. Post_max_size or upload_max_size werent allowing the image to processed as the image file size broke these settings.

PS the return for hasFile() is a boolean not the file itself.

Thanks matthew, I will give it a try now.

Last updated 2 years ago.
0

cilsilver said:

matthewburrow said:

I found this error before. My PHP.ini setting were the culprit for this. Post_max_size or upload_max_size werent allowing the image to processed as the image file size broke these settings.

PS the return for hasFile() is a boolean not the file itself.

Thanks matthew, I will give it a try now.

I did as advised but giving a new error that " Intervention \ Image \ Exception \ ImageNotWritableException " what could have caused this again?

Last updated 2 years ago.
0

The new error is Intervention \ Image \ Exception \ ImageNotWritableException. Can someone help out. I've been stuck with this for 4days now. Thanks

Last updated 2 years ago.
0

Are you sure the directory public_path().'/img/products/ exists? Do you have permission to write to it? If not, try a 777 chmod to products/

Last updated 2 years ago.
0

Yes it exists. I'm developing locally on windows. its also case sensitive,

Last updated 2 years ago.
0

Hi all !

I have also the same problem but with another function : Call to a member function getClientOriginalExtension() on a non-object

But everything is fine, my image is uploaded I can create a thumbnail and my function send me a 200 Response.

My form has a files => true but can't figure why this error is showing.

My function

	public function imageUpload(){

		$file = Input::file('image');
		$soliste = Soliste::findOrFail(Input::get('id'));


		$input = array('image' => $file);
		$rules = array(
			'image' => 'image'
		);
		$validator = Validator::make($input, $rules);
		if ( $validator->fails() )
		{
			return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]);

		}
		else {
			
			$destinationPath = 'uploads/avatars/';
			$old_image = $destinationPath.$soliste->avatar;
			$old_preview = 'preview_'.$old_image;

			// Deleting old images - preview & original
			if(File::isFile($old_image) && File::isFile($old_preview)){
				File::delete($old_image);
				File::isFile($old_preview)
			}

			$filename = Sanitize::string($soliste->firstname).'-'.Sanitize::string($soliste->lastname).'-'.str_random(5).'.'.$file->getClientOriginalExtension();

			// Upload Original version
			$file->move($destinationPath, $filename);
			
			// create a preview to speed-up upload and keep aspect ratio
			$preview = Image::make($destinationPath.$filename);
			$preview->resize(500,null,true);
			$preview_filename = $destinationPath.'preview-'.$filename;
			$preview->save($preview_filename);

			// saving model
			$soliste->avatar = $destinationPath.$filename;
			$soliste->save();
			
			return Response::json(['success' => true, 'file' => asset($preview_filename)]);
		}
	}

I also made a var_dump of the file inout and everything seems fine

file var output

object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(45) "Capture d’écran 2014-03-12 à 10.47.13.png" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "image/png" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(355823) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(36) "/Applications/MAMP/tmp/php/phptBWgOn" ["fileName":"SplFileInfo":private]=> string(9) "phptBWgOn"}{"success":true,"file":"http:\/\/localhost:8888\/solistes\/public\/uploads\/avatars\/preview-lucas-toumia-morissette-de-la-lavandiere-bKjkn.png"}

Last updated 2 years ago.
0

bidibule said:

Hi all !

I have also the same problem but with another function : Call to a member function getClientOriginalExtension() on a non-object

But everything is fine, my image is uploaded I can create a thumbnail and my function send me a 200 Response.

My form has a files => true but can't figure why this error is showing.

My function

  public function imageUpload(){

  	$file = Input::file('image');
  	$soliste = Soliste::findOrFail(Input::get('id'));


  	$input = array('image' => $file);
  	$rules = array(
  		'image' => 'image'
  	);
  	$validator = Validator::make($input, $rules);
  	if ( $validator->fails() )
  	{
  		return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]);

  	}
  	else {
  		
  		$destinationPath = 'uploads/avatars/';
  		$old_image = $destinationPath.$soliste->avatar;
  		$old_preview = 'preview_'.$old_image;

  		// Deleting old images - preview & original
  		if(File::isFile($old_image) && File::isFile($old_preview)){
  			File::delete($old_image);
  			File::isFile($old_preview)
  		}

  		$filename = Sanitize::string($soliste->firstname).'-'.Sanitize::string($soliste->lastname).'-'.str_random(5).'.'.$file->getClientOriginalExtension();

  		// Upload Original version
  		$file->move($destinationPath, $filename);
  		
  		// create a preview to speed-up upload and keep aspect ratio
  		$preview = Image::make($destinationPath.$filename);
  		$preview->resize(500,null,true);
  		$preview_filename = $destinationPath.'preview-'.$filename;
  		$preview->save($preview_filename);

  		// saving model
  		$soliste->avatar = $destinationPath.$filename;
  		$soliste->save();
  		
  		return Response::json(['success' => true, 'file' => asset($preview_filename)]);
  	}
  }

I also made a var_dump of the file inout and everything seems fine

file var output

object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(45) "Capture d’écran 2014-03-12 à 10.47.13.png" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(9) "image/png" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(355823) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(36) "/Applications/MAMP/tmp/php/phptBWgOn" ["fileName":"SplFileInfo":private]=> string(9) "phptBWgOn"}{"success":true,"file":"http:\/\/localhost:8888\/solistes\/public\/uploads\/avatars\/preview-lucas-toumia-morissette-de-la-lavandiere-bKjkn.png"}

Really, it made me frustrated for days now on solving the issue. got your error which was why i changed option but still issues. on Linux, it seems to work. My file permissions are accurate on windows. what could have been this problem?

Last updated 2 years ago.
0

I do not want to reopen old threads and if i crossed a forum guideline my apologies, however I've found that if i do like you etc

$file = Input::file('image');

and then try to do either of these

$file->getClientOriginalExtension(); 
$file->getClientOriginalName();

it will throw that error however if I would do like

Input::file('image')->getClientOriginalExtension();

It would work just fine.

0

hello everyone, As i have solved this problem and i have made use in my project for uploading images.

public function store(Request $request) {

$input = $request->all(); if(isset($input['photo']))

{ $destinationPath = 'image'; // upload path $fileName = str_replace(' ','',$input['name']).''.rand(11111,99999).'_'.$request->file('photo')->getClientOriginalName(); $move_photo = $request->file('photo')->move(base_path(). '/'.$destinationPath, $fileName); $allPath = $move_photo; $type = pathinfo($allPath, PATHINFO_EXTENSION); $data = file_get_contents($allPath); $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); $input['photo'] = $base64;

}

else {

$input['photo'] = null;
}

$files = new Files;
$files->photo = $input['photo'];
$files->save();

}

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

cilsilver cilsilver Joined 23 Dec 2013

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.