How can I solve File not found at path:... when rename file? (laravel) - image

I see from here : rename a directory or a file
I try like this :
$destination_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $product->photo;
$new_file_name = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $new_file_name;
// dd($destination_path, $new_file_name);
Storage::move($destination_path, $new_file_name);
There exist error :
[League\Flysystem\FileNotFoundException] File not found at path:
C:/xampp/htdocs/myshop/public/img/products/147/Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png
If I dd($destination_path, $new_file_name), the result :
C:\xampp\htdocs\myshop\public\img\products\147\Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png
C:\xampp\htdocs\myshop\public\img\products\147\147-hazard-chelsea.png
I try check Zl756CDHovOZpEZz0jBYk73UCfO4zNmYDVWgLPpw.png in folder 147, the file exist
Why there exist error?
Update :
I had find the solution. I use php script like this :
rename($destination_path, $new_file_name);. It works

Storage use C:/xampp/htdocs/myshop/storage/app
but your data store on public path
you can use \Storage::exists($path);
$destination_path = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $product->photo;
$new_file_name = public_path() . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'products'. DIRECTORY_SEPARATOR . $product->id . DIRECTORY_SEPARATOR . $new_file_name;
// dd($destination_path, $new_file_name);
if(\Storage::exists($destination_path)){
Storage::move($destination_path, $new_file_name);
}

Related

Laravel, How to automatic create thumb folder with Image/Intervation resize method

I need when upload article image, automatic upload Original Image Size and resize image in thumb folder.
but in this method i receive this error (thumb folder can not automatic create) :
Can't write image data to path (storage/upload/images/articles/1400/05/06/thumb/Bx1WRTtp9IgSZgnP8VE11627500167.jpg)
Upload Image Method :
protected function articleUploadImage($file, $folder, $size)
{
$d = jdate();
$year = $d->format('Y');
$month = $d->format('m');
$day = $d->format('d');
$direct = 'storage/upload/images/'. $folder . '/' . $year . '/' . $month . '/' . $day;
$directWithResize = 'storage/upload/images/'. $folder . '/' . $year . '/' . $month . '/' . $day . '/thumb';
$extension = $file->getClientOriginalExtension();
$fileName = Str::random(20) . time() . '.' . $extension;
// if (!is_dir($directWithResize)) {
// mkdir($directWithResize);
// }
//$path = Image::make($file->getRealPath());
//$path->resize(100, 100);
//$path->save(public_path($directWithResize . '/' . $fileName));
Image::make($file->getRealPath())->fit($size, null, function ($constraint) {
$constraint->aspectRatio();
})->save($direct . '/thumb/' . $fileName);
//$path = $file->store($direct);
//$newPath = $direct;
return $direct;
}
Before uploading an image, you should create a directory.
protected function articleUploadImage($file, $folder, $size)
{
$d = jdate();
$year = $d->format('Y');
$month = $d->format('m');
$day = $d->format('d');
$direct = 'storage/upload/images/'. $folder . '/' . $year . '/' . $month . '/' . $day;
$extension = $file->getClientOriginalExtension();
$fileName = Str::random(20) . time() . '.' . $extension;
if (!file_exists($direct . '/thumb/')) {
mkdir($direct . '/thumb/', 666, true);
}
Image::make($file->getRealPath())->fit($size, null, function ($constraint) {
$constraint->aspectRatio();
})->save($direct . '/thumb/' . $fileName);
return $direct;
}

How to install ArrowChat in laravel website

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

How to pass a method on cases i dont need to use Laravel,Trying to get property 'id' of non-object

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..?

PHP Session not getting updated in FireFox

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']);

Can We give the Code Pool Outside the "code" Directory in Magento

Can We give the Code Pool Outside the "code" Directory in Magento like
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', dirname(dirname(__FILE__)));
Mage::register('original_include_path', get_include_path());
//echo get_include_path();
//die('This is included path');
if (defined('COMPILER_INCLUDE_PATH')) {
$appPath = COMPILER_INCLUDE_PATH;
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once COMPILER_INCLUDE_PATH . DS . "Mage_Core_functions.php";
include_once COMPILER_INCLUDE_PATH . DS . "Varien_Autoload.php";
} else {
/**
* Set include path
*/
$paths[] = BP . DS . 'app' . DS . 'custom' . DS . 'custom';
/* 'custom' is My own folder name present out side the code directory */
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
include_once "Varien/Autoload.php";
}
it is Not working for me. is there any method to put the codepool out side the "Code" Directory in magento.
You can have your custom codepool by putting below line in your app/Mage.php
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'custom';
that I expect that you already know.
But if you want to keep your codepool in app/custom then creating symlink for your codepool will be the easiest way. Infect you can place your codepool anywhere in your system.
This is how you will create your symlink(considering /home/deependra/public_html is your magento root directory)
ln -s /home/deependra/public_html/app/custom/custom/ /home/deependra/public_html/app/code/custom

Resources