It might help to post your code here....
form inside modal problem
i have this upload picture form inside the modal now before i placed it into a single page and it works properly and restrict the user to upload without a file to upload.
now when i place my form upload code inside a modal it still display the error message for validation but it continue to save without a file to upload, how can i restrict that now?
any help will be a big learning for me :)
controller
public function uploadProfilePicture(Request $request) { $photos = Photo::where('user_id', '=', Auth::id())->get(); if (!$photos->isEmpty()) { foreach ($photos as $photo) { $photo->delete(); } } $this->validate($request, ['photoFilename' => 'required']); if (Input::hasFile('photoFilename')) {
$photo = Photo::create($request->all());
$request = $request->all();
$request['user_id'] = Auth::id();
$file = Input::file('photoFilename');
$photoname = md5($file . microtime());
// $file->move(public_path() . '/hphotos/xpf1/' . $request['user_id'] ."/", uniqid(). '.' .$file->guessClientExtension());
$file->move(public_path() . '/hphotos/xpf1/' . $request['user_id'] . "/", md5($file . microtime()) . '.' . $file->guessClientExtension());
$photo->profileimage = $photoname . '.' . $file->guessClientExtension();
$photo->user_id = $request['user_id'];
//
$photo->save();
}
return redirect('/');
}
view
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>
<div class="modal-dialog">
<div class="modal-header"> ×
`<h4 class="modal-title">Modal title</h4>
`<div class="modal-body">
-
@if ($errors->any())
@foreach ($errors->all() as $error)
".$error.""; ?>
@endforeach
@endif
{!! Form::open(array('url'=>'form-submit','files'=>true)) !!}
{!! Form::label('photoFilename','File',array('id'=>'','class'=>'')) !!}
{!! Form::file('photoFilename','',array('id'=>'','class'=>'')) !!}
<br/>
{!! Form::submit('Save') !!}
{!! Form::reset('Reset') !!}
{!! Form::close() !!}
</div>
<div class="modal-footer">
</div>
</div>
</div>
@dinis you really want us to build your application huh..
Please format your code properly, this is kinda unreadable...
@blackbird no im just trying to learn from experience that's the way how i learn things, by doing and seeing examples
I think you are going wrong here
$photoname = md5($file . microtime());
$file->move(public_path() . '/hphotos/xpf1/' . $request['user_id'] . "/", md5($file . microtime()) . '.' . $file>guessClientExtension());
$photo->profileimage = $photoname . '.' . $file->guessClientExtension();
You use the md5 method twice with microtime() so there is a change that the output of md5 is different. You need to use the $photoname variable everywhere instead of once
$photoname = md5($file . microtime());
$file->move(public_path() . '/hphotos/xpf1/' . $request['user_id'] . "/", $photoname . '.' . $file>guessClientExtension());
$photo->profileimage = $photoname . '.' . $file->guessClientExtension();
what do you mean by "so there is a change that the output of md5 is different"
does it mean that im getting the generated correct filename now and there is a chance that i might get a different filename?
I mean that if you do md5 twice with a time in it you might get different outputs in the proces because it's based on time. You only do it once and you use that as the filename
@blackbird thanks :) i get what you mean
is there any available open source package for private messaging except for pusher that you can recommend?
Please or to participate in this conversation.