how to fetch image link from database and image from folder in cakephp 3.6.7
please Help me,
thanks & regards,
Darshan
how to fetch image link from database and image from folder in cakephp 3.6.7
please Help me,
thanks & regards,
Darshan
while updating image link into database it will store first character only and shown error
Warning (2): Illegal string offset ānameā [APP/Controller\AuthexsController.php, line 92]
Warning (2): Illegal string offset ātmp_nameā [APP/Controller\AuthexsController.php, line 96]
Warning (2): Illegal string offset ānameā [APP/Controller\AuthexsController.php, line 96]
code is:
if($this->request->is(āpostā))
{
$profilepic=$this->request->data[āimageā][ānameā];
$myfolder= WWW_ROOT.DS."files".DS."uploads";
$dir = new Folder($myfolder, true, 0755);
move_uploaded_file($this->request->data['image']['tmp_name'], $myfolder.DS.$this->request->data['image']['name']);
$users_table = TableRegistry::get('users');
$users = $users_table->get($id);
$users->imagenew = $profilepic;
if($users_table->save($users))
$this->Flash->success('User is Updated');
$session = $this->request->session();
$session->write('user_id',$users);
return $this->redirect($this->Auth->redirectUrl());
}
help me plz
thanks & regards,
Darshan
I assume you image located in path : project/webroot/uploads/xxxxx.jpg
And xxxxx.jpg file name saved in tables users in fileds āimagenewā
To show the image in File: src/Template/Users/view.ctp
<?php
echo $this->Html->image('/uploads/'.$user->imagenew, ['alt' => 'Picture']);
okeyā¦,
but how to update the photo ā¦?
You can use like edit function and after save success, use move_uploaded_file to the uploads directory
this is my updatecontroller page
$profilepic=$this->request->data[āimageā][ānameā];
$myfolder= WWW_ROOT.DS.āfilesā.DS.āuploadsā;
$dir = new Folder($myfolder, true, 0755);
move_uploaded_file($this->request->data[āimageā][ātmp_nameā], $myfolder.DS.$this->request->data[āimageā][ānameā]);
error
Warning (2): Illegal string offset ānameā [APP/Controller\AuthexsController.php, line 92]
Warning (2): Illegal string offset ātmp_nameā [APP/Controller\AuthexsController.php, line 95]
Warning (2): Illegal string offset ānameā [APP/Controller\AuthexsController.php, line 95]
in database only first character is storing and shows errorā¦?
help me yarā¦
Can you share code HTML Form
html code: echo $this->Form->input(āimageā, [ātypeā => āfileā]);
controller code:
$profilepic=$this->request->data[āimageā][ānameā];
$myfolder= WWW_ROOT.DS.āfilesā.DS.āuploadsā;
$dir = new Folder($myfolder, true, 0755);
move_uploaded_file($this->request->data[āimageā][ātmp_nameā], $myfolder.DS.$this->request->data[āimageā][ānameā]);
$users_table = TableRegistry::get(āusersā);
$users = $users_table->get($id);
$users->imagenew = $profilepic;
if($users_table->save($users))
$this->Flash->success(āUser is Updatedā);
Do you put this code in your form helper?
echo $this->Form->create($users, ['type' => 'file']);
Just want to know, you put this array in the form ['type' => 'file']
i tried its Its not working
ya bro working i forgot to add
āenctypeā => āmultipart/form-dataā
its not workingā¦
Yes, and Good job. Itās point I want to you find it, because value from your FROM not passing multipart/form-data
.
Maybe like this put in value of existing name to new input as 'old_nameā
echo $this->Form->control('old_name',['value'=>$user->name]);
In Controller, for delete the file.
$oldprofilepic=$this->request->data[āimageā][āold_nameā];
$myfolder= WWW_ROOT.DS.āfilesā.DS.āuploadsā;
$dir = new Folder($myfolder, true, 0755);
$file = new File($myfolder.DS.$oldprofilepic);
$file->delete();
$file->close();
OR Just simple like unlink($myfolder.DS.$oldprofilepic);
This code just the idea. Not tested.
that is not workingā¦
how to get jQuery function to cakephp headerā¦?
plz help meā¦
How you declare jquery lib?
i tried as script but its not workingā¦
Basically, we put file
*.js in webroot/js
*.css in webroot/css
*.jpg in webroot/img
in src/Template/Layout/defau.ctp for example configure for bootstrap
<!DOCTYPE html>
<html>
<head>
<!-- CSS Bootstrap 3.3.6 -->
<?php echo $this->Html->css('bootstrap.min'); ?>
<!-- Custom style exp: style.css-->
<?php echo $this->Html->css('style'); ?>
<?= $this->fetch('meta') ?>
<?= $this->fetch('css') ?>
<?= $this->fetch('script') ?>
</head>
<body>
<?= $this->Flash->render() ?>
<div class="container clearfix">
<?= $this->fetch('content') ?>
</div>
<!-- jQuery 2.2.3 -->
<?php echo $this->Html->script('jquery-2.2.3.min'); ?>
<!-- JS Bootstrap 3.3.6 -->
<?php echo $this->Html->script('bootstrap.min'); ?>
<!-- Custom Js exp: tools.js-->
<?php echo $this->Html->css('tool'); ?>
</body>
</html>