I've been stuck integrating arrowchat with laravel.
I purchased arrowchat and by install documentation, I did.
But I can't install.
Is it possible to integrate arrowchat to laravel?
I think it's possible.
If possible, how to do that?
To solve this, we should bootstrap Laravel in the integration file of Arrowchat.
So the start of the integration.php should be start like this:
$base_path = dirname(dirname(dirname(dirname(__FILE__))));
require_once($base_path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
require_once($base_path . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . 'autoload.php');
$app = require_once($base_path . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . 'app.php');
try {
$app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();
} catch(\Exception $ex) {
}
function get_user_id() {
$userid = NULL;
global $app;
$app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();
if($app['auth']->user()!= NULL){
$userid = $app['auth']->user()->id;
}
return $userid;
}
Source
Related
I am trying to upload an image in Laravel. Getting the following error:
"message": "Could not move the file \"C:\\xampp\\tmp\\php84AA.tmp\" to \"F:\\bvend\\bvend-web\\public\\uploads/products\\bvend-product-1666274539.jpg\" (move_uploaded_file(): Unable to move "C:\\xampp\\tmp\\php84AA.tmp" to "F:\\bvend\\bvend-web\\public\\uploads/products\\bvend-product-1666274539.jpg").",
"exception": "Symfony\\Component\\HttpFoundation\\File\\Exception\\FileException",
"file": "F:\\bvend\\bvend-web\\vendor\\symfony\\http-foundation\\File\\UploadedFile.php",
"line": 177,
"trace": [ .... ]
My code is given below:
public function uploadImage($image, $image_path)
{
$path = config('global.' . $image_path . '_image_path');
file_exists($image) && unlink($image);
$image_name = 'bvend-' . $image_path . '-' . time() . '.' . $image->getClientOriginalExtension();
$image->move($path, $image_name); // $path: public_path('uploads/products')
return $image_name;
}
I understand its a simple issue but still no clue where it causing issue.
Edit
#WahidulAlam Please, try removing file_exists($image) && unlink($image);
– steven7mwesigwa - https://stackoverflow.com/posts/comments/130904221?noredirect=1
#WahidulAlam You're essentially deleting the temporary file/image before its copied or moved.
– steven7mwesigwa - https://stackoverflow.com/posts/comments/130904261?noredirect=1
ah this is the catch !! thanks a lot.
– Wahidul Alam - https://stackoverflow.com/posts/comments/130904399?noredirect=1
Specifying A File Name
If you do not want a filename to be automatically assigned to your
stored file, you may use the storeAs method, which receives the
path, the filename, and the (optional) disk as its arguments:
$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);
You may also use the putFileAs method on the Storage facade, which
will perform the same file storage operation as the example above:
$path = Storage::putFileAs(
'avatars', $request->file('avatar'), $request->user()->id
);
Solution
public function uploadImage(\Illuminate\Http\UploadedFile $image, $image_path)
{
return $image->storePubliclyAs(
config('global.' . $image_path . '_image_path'),
'bvend-' . $image_path . '-' . time(),
["disk" => "public"]
);
}
Addendum
Don't forget to create a symbolic link from public/storage to storage/app/public. I.e:
php artisan storage:link.
The Public Disk
Once a file has been stored and the symbolic link has been created,
you can create a URL to the files using the asset helper:
echo asset('storage/file.txt');
In Summary
$savedPath = $request->file("***REQUEST-INPUT-IMAGE-NAME-HERE***")->storePubliclyAs(
"***IMAGE-PATH-HERE***",
"***CUSTOM-FILENAME-HERE***",
["disk" => "public"]
);
I am using this methodology in Laravel 9.
try this:
public function uploadImage($image, $image_path)
{
// $path = config('global.' . $image_path . '_image_path');
file_exists($image) && unlink($image);
$image_name = 'bvend-' . $image_path . '-' . time() . '.' . $image->getClientOriginalExtension();
//$image->move($path, $image_name); // $path: public_path('uploads/products')
$image->move(public_path('/images'), $image_name);
return $image_name;
}
Hi there I have this problem on Laravel, I don't know how to explain it but I'll give my best, so forgive me if I am not to clear.
I have this on my controller for uploading images:
public function setUniqueNameAttribute(){
$this->unique_name = md5(Auth::user()->id . time());
}
public function getUniqueNameAttribute(){
return $this->unique_name;
}
public function uploadImage($request, $element, $id) {
if ($request->hasFile('question_image') || $request->hasFile('image_path') || $request->hasFile('avatar') || $request->hasFile('contact_image')) {
$thumbnailsRules = require_once __DIR__ . '/ThumbnailRules.php';
$this->setUniqueNameAttribute();
if($element == 'questions'){
$ImageToUpload = $request->file('question_image');
}elseif($element == 'answers'){
$ImageToUpload = $request->file('image_path');
}elseif($element == 'users'){
$ImageToUpload = $request->file('avatar');
}elseif($element == 'contacts'){
$ImageToUpload = $request->file('contact_image');
}
//create folders if they do not exist
foreach ($thumbnailsRules as $key => $rule) {
if (File::exists(storage_path('/app/public/institutions/' . $this->institution_storage . '/images/' . $element . '/' . $id . '/' . $rule['name'] . '/')) == false) {
Storage::disk('public')->makeDirectory('/institutions/' . $this->institution_storage . '/images/' . $element . '/' . $id . '/' . $rule['name']);
Storage::disk('public')->makeDirectory('/institutions/' . $this->institution_storage . '/images/' . $element . '/' . $id . '/original/');
}
}
//save the photos to the server
$image = Image::make($ImageToUpload);
$image->save(storage_path('/app/public/institutions/' . $this->institution_storage . '/images/' . $element . '/' . $id . '/original/' . $this->getUniqueNameAttribute() . '.jpeg'));
foreach ($thumbnailsRules as $key => $rule) {
$image = Image::make($ImageToUpload)->resize($rule['width'], $rule['height'], function ($c) {
$c->aspectRatio();
$c->upsize();
});
$image->save(storage_path('/app/public/institutions/' . $this->institution_storage . '/images/' . $element . '/' . $id . '/' . $rule['name'] . '/' . $this->getUniqueNameAttribute() . '.jpeg'));
}
}
}
This works fine for the question_image, image_path and avatar because this I use after I am logged in so I can use this:
$this->setUniqueNameAttribute();
But for contact image I have to use this before logged in so I don't need to use this:
$this->setUniqueNameAttribute();
This gives me this error:
Trying to get property 'id' of non-object
Is there a way to pass through this without getting an error..?
After deploying my laravel project from local to Apache web server, all works correctly except images link. Here the code:
Images are stored in:
storage/app/public/photos
after i've run command:
php artisan storage:link
Images are linked at:
public/storage/photos
Controller:
if ($request->hasFile('photo')) {
$extension = $request->file('photo')->getClientOriginalExtension();
$file = $request->file('photo');
$photo = $file->storeAs('public/photos', 'foto-' . time() . '.' . $extension);
$user->photo = $photo;
$user->save();
}
Images are uploaded correctly on storage/app/public/photos and correctly linked in public/storage/photos but it doesn't display on frontend.
in blade, i've tried to use Storage::url to retrieve the path
{{Storage::url($user->photo)}}
and asset()
{{asset($user->photo)}}
in both cases, image doesn't exist
The public path of image is:
http://mywebsite.com/storage/photos/foto-1522914164.png
You should Use url function to show your image like below way.
url($user->photo);
I'd suggest to change the controller code as follows:
if ($request->hasFile('photo')) {
$extension = $request->file('photo')->getClientOriginalExtension();
$file = $request->file('photo');
$photoFileName = 'foto-' . time() . '.' . $extension;
$photo = $file->storeAs('public/photos', $photoFileName);
$user->photo = 'photos/' . $photoFileName;
$user->save();
}
Then you can use {{asset($user->photo)}} in your blade.
on my webspace, it seems that the only way to display image correctly is to create a custom route that read and serve the image.
i'm solved like this:
i'm storing only image name in db:
if ($request->hasFile('photo')) {
$extension = $request->file('photo')->getClientOriginalExtension();
$file = $request->file('photo');
$photoFileName = 'photo-' . $model->id . '.-' . time() . '.' . $extension;
$photo = $file->storeAs('public/photos', $photoFileName);
$store = $photoFileName;
}
then, i've create custom route that read images and display them:
Route::get('storage/{filename}.{ext}', function ($filename, $ext) {
$folders = glob(storage_path('app/public/*'), GLOB_ONLYDIR);
$path = '';
foreach ($folders as $folder) {
$path = $folder . '/' . $filename . '.' . $ext;
if (File::exists($path)) {
break;
}
}
if (!File::exists($path)) {
abort(404);
}
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header('Content-Type', $type);
return $response;
});
in blade, i'm using Storage to display image:
{{ Storage::url($photo->photo) }}}
I am facing a strange error. It is related to updating the php session.
I have a site whose login/logout works perfectly in chrome,safari and IE etc. But in firefox it is not working. When I login using firefox, the logout button seems to be dead or something. It just doesnt let me logout. Even if I manually type the logout link, it still doesnt do anything and keeps me logged in. I am not doing anything complex at all.
Any ideas why the same code works in chrome, IE and safari but not in firefox?
Let me know,
Thanks.
============================LOGOUT CODE===============================
public function logout() {
$this->session->unset_userdata('smallpoint_username');
$this->session->sess_destroy();
redirect(base_url() . 'forum/update_session.php?hasher = ' . time() . time() . time() . time() . time() . time() . '&&nohasher=' . time() . time() . time() . time() . time() . time() . '&&op=2', 'location', 301);
}
================SESSION SETTING CODE in LOGIN===============================
$session_array = array(
'smallpoint_username' => $insertData['username'],
'smallpoint_full_name' => $insertData['full_name'],
'smallpoint_user_type' => $insertData['user_type'],
'smallpoint_user_id' => $userData['id'],
'smallpoint_user_snap' => '',
'is_logged_in' => 1,
);
$this->session->set_userdata($session_array);
redirect(base_url() . 'forum/update_session.php?hasher = ' . time() . time() . time() . time() . time() . time() . '&&nohasher=' . time() . time() . time() . time() . time() . time() . '&&thisisid=' . $userData['id'] . '&&thisisrole=' . $insertData['role'] . '&&thisisname=' . $insertData['username'] . '&&op=1', 'location', 301);
=====================update_session.php======================
session_start();
require 'includes.php';
if ($_GET['op'] == 1) {
$_SESSION[TABLES_PREFIX . 'sforum_logged_in'] = true;
$_SESSION[TABLES_PREFIX . 'sforum_user_id'] = $_GET['thisisid'];
$_SESSION[TABLES_PREFIX . 'sforum_user_role'] = $_GET['thisisrole'];
$_SESSION[TABLES_PREFIX . 'sforum_user_username'] = $_GET['thisisname'];
} else {
unset($_SESSION[TABLES_PREFIX . 'sforum_logged_in']);
unset($_SESSION[TABLES_PREFIX . 'sforum_user_id']);
unset($_SESSION[TABLES_PREFIX . 'sforum_user_role']);
unset($_SESSION[TABLES_PREFIX . 'sforum_user_username']);
setcookie(TABLES_PREFIX . COOKIE_NAME, "", time() - 3600);
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
Try to add the following to your code.
session_save_path("/tmp");
session_start();
I got the same problem in firefox and it works fine
session_save_path("/tmp"); // CREATE this Folder in the root
session_start();
require 'includes.php';
if ($_GET['op'] == 1) {
$_SESSION[TABLES_PREFIX . 'sforum_logged_in'] = true;
$_SESSION[TABLES_PREFIX . 'sforum_user_id'] = $_GET['thisisid'];
$_SESSION[TABLES_PREFIX . 'sforum_user_role'] = $_GET['thisisrole'];
$_SESSION[TABLES_PREFIX . 'sforum_user_username'] = $_GET['thisisname'];
} else {
unset($_SESSION[TABLES_PREFIX . 'sforum_logged_in']);
unset($_SESSION[TABLES_PREFIX . 'sforum_user_id']);
unset($_SESSION[TABLES_PREFIX . 'sforum_user_role']);
unset($_SESSION[TABLES_PREFIX . 'sforum_user_username']);
setcookie(TABLES_PREFIX . COOKIE_NAME, "", time() - 3600);
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
I run into a problem using session in .php file i attached in jumi
How do i set a session in in that page? when i use :
//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();
if(isset($_GET['id'])){
var_dump($id= $_GET['id[i]']);
} else {echo "No session ";}
// code connect to db
// render out the items
//
foreach($rows as $i=>$row){
$id[$i] = $row['rid'];
$name[$i] = $row['rname'];
$view .= '<tr>
<td>'.$id[$i].'</td>
<td>'.$name[$i].'</td>';
?>
}
<p><?php echo $view.'</tr></table>'; ?> </p>
......
It doesn't let me find the sub-page of id=1 that I clicked .
What is the better way to deal with this kind of thing?
thank you.
You have a syntax error try this before you go any further:
</php
//this define and require I use from reading the other papers
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );
require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
$mainframe = JFactory::getApplication('site');
$session = &JFactory::getSession();
if(isset($_GET['id'])){
var_dump($id= $_GET['id[i]']);
} else {
echo "No session ";
}
// code connect to db
// render out the items
//
foreach($rows as $i=>$row){
$id[$i] = $row['rid'];
$name[$i] = $row['rname'];
$view .= '<tr>
<td>'.$id[$i].'</td>
<td>'.$name[$i].'</td>';
}
?>
<p><?php echo $view.'</tr></table>'; ?></p>
Looking at the way Jumi includes PHP files, you should start with:
defined('_JEXEC') or die('Restricted access');
This will prevent the PHP file from being executed via a direct HTTP request (if you look at the example blogger file included with Jumi you will see this line). The define statements you have, initialise globals that Joomla! code uses to make sure a request has entered through the right path.
Apart from that, as mentioned by #travega you close of the PHP with ?> before you close the foreach()