i want build an Profile Picture Avatar Upload and display it in the Profile for every user.
Buts dont work with my method.
My Avatar Upload code:
<div class="form-group">
<div class="form-group">
<label for="exampleInputFile"><img src="/img/photos.png" height="80" width="80"> Upload Avatar:</label>
<input type="file" id="exampleInputFile" name="profileimage"></font></br>
</div>
</div>
Code where everyone see it in Profile:
<div class="pull-left margin-left-25">
#if($user->profileimage == false)
<img src="/img/icon.png" height="80" width="80">
#endif
#if($user->profileimage == true)
<img src="{{$user->profileimage}}" height="80" width="80">
#endif
ProfileController image content (Dont work for me):
if ($request->hasFile('image')) {
$file = $request->file('profileimage');
$size = $request->file('profileimage')->getSize();
if ($size > 500000) {
session()->flash('errormessage','Image is too large');
return redirect()->back()->withInput();
}
if (substr($file->getMimeType(), 0, 5) !== 'profileimage') {
session()->flash('errormessage','File is not an image');
return redirect()->back()->withInput();
}
if ($file->isValid()) {
$path = $request->profileimage->store('uploads','public');
} else {
session()->flash('errormessage','Image is not valid');
return redirect()->back()->withInput();
}
}
if ($request->image !== null) {
$product->image = $path;
}
What i have done wrong?
Thanks!
Why don't use Validator class?It will be so much easier than what you have coded. As the following,
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:500000',
]);
Add the above code inside the method in which you store the file and do your things.
It will do the validation for you, then continue whatever you want to do with the file. For more options please check the link provided.
Also, in your HTML code. You need to have a form in first place, action and its method, so your code should be:
<div class="form-group">
<div class="form-group">
<form action="{{ route('profile'}}" method="post">
<label for="exampleInputFile"><img src="/img/photos.png" height="80" width="80"> Upload Avatar:</label>
<input type="file" id="exampleInputFile" name="profileimage"></font></br>
</form>
</div>
</div>
And in your web.php, you should have the following line:
Route::get('/URL', 'ProfileController#MethodName')->name('profile');
Related
I want to add Recaptcha, the second version, not another version, and I want it to be in ASP.NET Core, not MVC, and I searched a lot and did not find the solution.. I hope for help
I have a login controller :
public IActionResult Login([Bind("Username , Password")] User userLogin)
{
const string id = "id";
var auth = _context.Users.Where(x => x.Username == userLogin.Username &&
x.Password == userLogin.Password).SingleOrDefault();
var x = _context.Users.Where(x => x.Username == userLogin.Username && x.Password
== userLogin.Password).Select(i => i.UserId).FirstOrDefault();
if (auth != null)
{
// 1 > admin
// 2 > Accountant
// 3 > customer
switch (auth.RoleId)
{
case 1: // admin
HttpContext.Session.SetInt32(id, (int)x);
return RedirectToAction("Index", "Home");
case 2:
HttpContext.Session.SetInt32(id, (int)x);
return RedirectToAction("AccountantDashboard", "Home");
case 3:
HttpContext.Session.SetInt32(id, (int)x);
return RedirectToAction("Home", "Home");
}
}
return View();
}
and another for view (head and body)
<form asp-action="Login" enctype="multipart/form-data">
<div class="input-group">
<label asp-for="Username" class="input--style-2" placeholder="username"></label>
<input asp-for="Username" class="input--style-2" />
<span asp-validation-for="Username" class="text-danger"></span>
</div>
<div class="input-group">
<label asp-for="Password" class="input--style-2" placeholder="Password"></label>
<input asp-for="Password" type="password" class="input--style-2" />
<span asp-validation-for="Password" class="text-danger"></span>
</div>
<div class="p-t-30">
<button class="btn btn--radius btn--green" type="submit" value="Create">Login</button>
</div>
<div style="position: relative ; left: 350px ; bottom: -50px">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Home">Or back to home page</a>
</div>
</form>
As far as I know, the reCaptcha "v2" is build based on js and we could directly use it inside the html page.
We could use it like this, firstly put below codes inside your view and it is used to put the g-recaptcha and it contains a callback method, if this method is called that means the user has passed the validation and you could show the button by using JQuery or javascript.
<div class="g-recaptcha" data-callback="recaptcha_callback" data-sitekey="xxxxx"></div>
Like this:
<script type="text/javascript">
function recaptcha_callback(){
$('#login).show();
}
</script>
More details, you could refer to this article.
My aim is to update a partial to show course dates when a date range is specified and submitted.
I have a function that works as expected.
user selects a start date
user selects an end date
the user clicks search
results are logged to the console
Here is the function
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
return $dates;
}
Here is the markup
<form class="row gx-3 align-items-center" data-request="onFetchDataFromServer" data-request-success="console.log(data)"">
<div class="col-12 col-lg pxp-has-left-border">
<div class="input-group mb-3 mb-lg-0">
<span class="input-group-text"><span class="fa fa-calendar-o"></span></span>
<input type="date" class="form-control" id="startPicker" name="start_date" placeholder="Choose a start date">
</div>
</div>
<div class="col-12 col-lg pxp-has-left-border">
<div class="input-group mb-3 mb-lg-0">
<span class="input-group-text"><span class="fa fa-calendar-o"></span></span>
<input type="date" class="form-control" id="endPicker" name="end_date" placeholder="Choose an end date">
</div>
</div>
<div class="col-12 col-lg-auto">
<button type="submit">Search dates</button>
</div>
</form>
So the rather than logging the results to the console, I now would like to update a partial.
I have a partial in the view called 'course/metas'.
Can someone please help me?
Thanks in advance.
You can try something like this. Check the documents here.
This is for a page's PHP section:
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
$this['dates'] = $dates;
return [
'#myDiv' => $this->renderPartial('coursemetas')
];
}
This is for component plugin:
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
$this->page['dates'] = $dates;
return [
'#myDiv' => $this->renderPartial('#coursemetas')
];
}
Note the # sign sent with the renderPartial as this tells the framework to look inside the plugin folder for the partial. Or you can specify the partial path by component and partial name like this return $this->renderPartial('course::coursemetas');.
Hi I'm using unisharp laravel-filemanager for user to upload their products photos
when the image uploaded
this address will save in database
/photos/44/606074649c651.jpg
and I can use it by
{{asset('storage/'.$product->cover_img)}}
and Thumbnail saved in this address
/photos/44/thumbs/606074649c651.jpg
How can I get the address of thumbnail and how can I use it in blade?
This is the answer
#php($lastSlash = strrpos($product->cover_img,"/"))
src="{{asset('storage/'.substr_replace($product->cover_img, 'thumbs/', $lastSlash+1) .'' .substr($product->cover_img ,$lastSlash+1))}}"
One way to save it in the database is to add a hidden type input to the image's thumb, inside the stand-alon-button.js file.
// set or change the preview image src
items.forEach(function (item) {
target_preview.append(
$('<img>').css('height', '5rem').attr('src', item.thumb_url),
$('<input type="hidden" name="thumbnail">').attr('value', item.thumb_url)
);
});
Input:
<div class="input-group">
<span class="input-group-btn">
<a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
<i class="fa fa-picture-o"></i> Choose
</a>
</span>
<input id="thumbnail" class="form-control" type="text" name="image">
</div>
<div id="holder" style="margin-top:15px;max-height:100px;"></div>
you can use a function like this:
function getThumbs($url=""){
$base = basename($url);
if (strpos($url, 'https://') !== false or strpos($url, 'http://') !== false) {
return str_replace($base, "thumbs/".$base, $url);
}else{
$preUrl = "storage/";
$beforeBase = str_replace($base, "",$url);
return $preUrl.$beforeBase.'thumbs/'.$base;
}
}
and in your blade use:
<img src="{{ getThumbs($product->cover_img) }}" .../>
I need to pull in data to my view but this doesn't work:
return view ('sub-domain', ['worker' => $worker ]);
Here is my code:
public function aerospace(Request $request , Worker $worker ){
$worker = $worker->newQuery();
if ($request->has('profession')) {
$worker->where('profession', $request->input('profession'));
}
if ($request->has('state')) {
$worker->where('state', $request->input('state'));
}
if ($request->has('local_govt')) {
$worker->where('local_govt', $request->input('local_govt'));
}
return $worker->get();
The above code brings out an array of data from the database which I can then filter with "domain/sub-domain?state=xyz"
Now when I try to pass in the data into my views using
return view ('sub-domain', ['worker' => $worker ]);
The page is loaded but no $worker data is loaded on the page. How can I pull the data? Here is my view file
<div class="row">
<form method="GET" action="">
Profession:<input type="text" name="profession"> State:<input type="text" name="state"> Local Govt:<input type="text" name="local_govt">
<button type="submit">Filter</button>
</form>
</div>
<div class="row">
#foreach ($worker as $worker)
<div class="col-lg-3 col-md-6">
<div class="member">
<div class="pic"><img src="avatar/{{$worker->avatar}}" alt=""></div>
<div class="details">
<h4>{{$worker->name}} {{$worker->l_name}}</h4>
<span>{{$worker->profession}}</span><br>{{ $worker->state }}
</div>
</div>
</div> #endforeach
</div>
I want to filter data by certain parameters, if there's a better way to do that please do let me know. But first I need the data to display.
You are returning a query instance, not a collection or singular model. That's why the get() method works. So first do:
$worker = $worker->get();
I want to know how I can upload an image and save its name in a database when using Codeigniter.
I am using a simple form tag for this, like:
<form action="./myaccount/index/" method="post" enctype="multipart/form-data">
<div>
<label for="pic">picture</label>
<input type="file" id="pic" name="pic" />
</div>
<input id="register-btn" name="register" type="submit" value="ok" class="input-text custom-btn">
</form>
Here's my controller:
public function index() {
$user = new User($_SESSION['user_id']);
if($this->input->post()){
$user->pic = $this->input->post('pic');
if($this->input->post('password') == $this->input->post('confirm')){
$user->password=md5(sha1(sha1($this->input->post('password'))));
$user->save();
$this->data['success'] = "done";
}else{
$this->errors[] = "error";
}
}
$this->data['user'] = $user;
$this->data['errors'] = $this->errors;
$this->template->set_layout('myaccount');
$this->template->build('profile',$this->data);
}
I checked the manual but I can't understand what they are doing.
Im' trying to make a controler function for this that will insert all the values in the database and also upload the image file.