How do I make different sessions on the site - session

I am using session_start ();
I want to make each page or each folder has its own session
Example:
When you request mysite.com/A opens new session
When asked mysite.com/B opens new session
How so?

It is not clear as to what you mean by opening new session in each folder. If you meant to say that you want a session variable on each folder and the value of this variable should change from folder to folder:
Say, you have a session variable $_SESSION['folderName'] and you want to achieve:
$_SESSION['folderName'] = 'A'; // When in folder mysite.com/A
$_SESSION['folderName'] = 'B'; // When in folder mysite.com/B
Then you can do:
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', $_SERVER['REQUEST_URI_PATH']);
//now when the URL is mysite.com/A, $segments[0] will
// have mysite.com and $segments[1] will have 'A'
So, on each file on each folder, you can do:
<?
session_start();
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', $_SERVER['REQUEST_URI_PATH']);
$_SESSION['folderName'] = $segments[1];
?>

Related

delete old image while updating the field

I am doing CRUD operations for images. when I am doing the update operation image gets updated but the old image doesn't delete. The following code updates only the file name in the database but I need to remove the old image from the destination folder too while updating else the folder size will become too large. Any ideas would be great. Here my code.
<input type="file" name="profileimage" value="{{ isset($editabout) ? $editabout->profileimage : '' }}" class="custom-file-input" id="exampleInputFile">
Here is my controller
public function update(updateAboutusProfile $request, AboutUs $about)
{
$data=$request->only(['profiletext']);
if($request->hasFile('profileimage')){
$profileimage = $request->profileimage->store('aboutus', 'public');
$oldimage = $about->profileimage;
Storage::delete($oldimage);
$data['profileimage'] = $profileimage;
}
$about->update($data);
toastr()->success('Profile updated successfully');
return redirect(route('about.index'));
//
}
What can be the error I need to resolve,
thank you
Try setting the disk you used to store the file
Storage::disk('public')->delete($oldimage);
Delete image from your server, you have to reference location of file in directory server, means you could not reference by url link to delete it.
Laravel file is locate in public folder.
Example: your files are located in public/images
$image_path = "/images/filename.ext"; // Value is not URL but directory file path
if(File::exists($image_path)) {
File::delete($image_path);
}
Enjoy ;)
You should save the path of the file to the database and then simply remove it using \Storage::delete() facade.
Store image using hash name
if($request->hasFile('profileimage')){
$store_path = 'aboutus';
$profileimage = $request->profileimage->store($store_path,'public');
$oldimage = $about->profileimage;
$file_address = $store_path.'/'.$request->profileimage->hashName();
\Storage::disk('public')->delete($oldimage);
$data['profileimage'] = $file_address;
}
Store image using original name
if($request->hasFile('profileimage')){
$store_path = 'aboutus';
$profileimage = $request->profileimage->storeAs($store_path, $uploadedFile->getClientOriginalName(),'public');
$oldimage = $about->profileimage;
$file_address = $store_path.'/'.$request->profileimage->getClientOriginalName();
\Storage::disk('public')->delete($oldimage);
$data['profileimage'] = $file_address;
}
Delete the old image while updating
public function update(Request $request, $id)
{
// other updates
if ($request->hasFile('image')) {
//delete old image if exist
if (File::exists(public_path($oldImage))) {
File::delete(public_path(oldImage));
}
//new image process
}
}

Error index.php not writeable Administrator index.php not writeable In opencart

i've got problem when i install vqmod in opencart the error say
index.php not writeable
Administrator index.php not writeable
i have no index.php file in my root opencart ,
Admin/index.php
<?php
// Version
define('VERSION', '2.3.0.2');
// Configuration
if (is_file('config.php')) {
require_once('config.php');
}
// Install
if (!defined('DIR_APPLICATION')) {
header('Location: ../install/index.php');
exit;
}
// Startup
require_once(DIR_SYSTEM . 'startup.php');
start('admin');
vqmod/install/index.php
// CHANGE THIS IF YOU EDIT YOUR ADMIN FOLDER NAME
$admin = 'admin';
// Counters
$changes = 0;
$writes = 0;
// Load class required for installation
require('ugrsr.class.php');
// Get directory two above installation directory
$opencart_path = realpath(dirname(__FILE__) . '/../../') . '/';
// Verify path is correct
if(!$opencart_path) die('COULD NOT DETERMINE CORRECT FILE PATH');
$write_errors = array();
if(!is_writeable($opencart_path . 'index.php')) {
$write_errors[] = 'index.php not writeable';
}
if(!is_writeable($opencart_path . $admin . '/index.php')) {
$write_errors[] = 'Administrator index.php not writeable';
}
if(!empty($write_errors)) {
die(implode('<br />', $write_errors));
}
// Create new UGRSR class
$u = new UGRSR($opencart_path);
// remove the # before this to enable debugging info
#$u->debug = true;
// Set file searching to off
$u->file_search = false;
// Attempt upgrade if necessary. Otherwise just continue with normal install
$u->addFile('index.php');
$u->addFile($admin . '/index.php');
$u->addPattern('~\$vqmod->~', 'VQMod::');
$u->addPattern('~\$vqmod = new VQMod\(\);~', 'VQMod::bootup();');
$result = $u->run();
if($result['writes'] > 0) {
if(file_exists('../mods.cache')) {
unlink('../mods.cache');
}
die('UPGRADE COMPLETE');
}
$u->clearPatterns();
$u->resetFileList();
// Add catalog index files to files to include
$u->addFile('index.php');
// Pattern to add vqmod include
$u->addPattern('~// Startup~', '// VirtualQMOD
require_once(\'./vqmod/vqmod.php\');
VQMod::bootup();
// VQMODDED Startup');
$result = $u->run();
$writes += $result['writes'];
$changes += $result['changes'];
$u->clearPatterns();
$u->resetFileList();
// Add Admin index file
$u->addFile($admin . '/index.php');
// Pattern to add vqmod include
$u->addPattern('~// Startup~', '//VirtualQMOD
require_once(\'../vqmod/vqmod.php\');
VQMod::bootup();
// VQMODDED Startup');
$result = $u->run();
$writes += $result['writes'];
$changes += $result['changes'];
$u->addFile('index.php');
// Pattern to run required files through vqmod
$u->addPattern('/require_once\(DIR_SYSTEM \. \'([^\']+)\'\);/', 'require_once(VQMod::modCheck(DIR_SYSTEM . \'$1\'));');
// Get number of changes during run
$result = $u->run();
$writes += $result['writes'];
$changes += $result['changes'];
// output result to user
if(!$changes) die('VQMOD ALREADY INSTALLED!');
if($writes != 4) die('ONE OR MORE FILES COULD NOT BE WRITTEN');
die('VQMOD HAS BEEN INSTALLED ON YOUR SYSTEM!');
you need to do two things
1)open vqmod/install/index.php
find the following code
$admin = 'admin';
change its value to your admin folder name that you have changed to
$admin = 'youradminfoldername';
2)open vqmod/pathReplaces.php
find the following code (if there is no,add it)
$replaces[] = array('~^admin\b~', 'xxxxx');
change xxxxx to your current admin folder name.
after you have these two things,even if it still show such infomation,
you should be ok to install extension.
I have tested this method ,it works for me.
another solution I guess maybe is to delete vqmod folder and reupload vqmod-opencart-2.6.1,and then only need to modify vqmod/pathReplaces.php,it should works
It probably means that you've deleted the file. You might have to reinstall the Opencart or upload the file from default opencart source files.
Open cPanel File Manager Set permission to 777 for the file

Codeigniter session in sub directory

I am using CI version 3 with session driver as files. I just want to get session variables in some sub directory but print_r($_SESSION) not printing my saved session variables.
Can some one help how do i get session in sub-directory.
In addition, I have tried below and getting some variable checking set or not but don't know how to get all variables value from saved session files that I am saving in my tmp folder at root
if(isset($_COOKIE['ci_session'])) {
$file = '../tmp/ci_session'.$_COOKIE['ci_session'];
if(file_exists($file)){
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));
//echo $contents;
$pos = strpos($contents, 'logged_in');
if ($pos === false) {
echo "Logged out";
} else {
echo "Logged in";
}
fclose($handle);
}
}
Change your config.php file configuration where you want to get your all session data
$config['sess_save_path'] = APPPATH.'test';
Above config will store all sessions in application/test directory

Laravel path to image

Image Move to folder using the tool move ()...
But when I want to display it in html showing me the full path...
for example on inspect elements show this: /opt/lampp/htdocs/app/uploads/
develop my app on localhost
$destinationPath = 'uploads/';
$filename = Input::file('file')->getClientOriginalName();
Input::file('file')->move($destinationPath, $filename);
Keep in mind only the "public" directory is actually web accessible, so if you are moving something to anything not in "public", then it won't be web accessible. You can get around this by either a) moving it to somewhere in your 'public' directory, and then building a url to that (I suggest URL::to('/path/to/your/file')), or you can build a controller function which simply spits out your file.
I have done something similar in my app, with a controller that grants access (to authorized users only) to view uploaded content in a folder under app/userdocs:
// Read file then spit it out
$filepath = $doc->file;
$imagecontents = File::get(app_path().'/userdocs/' . $filepath);
if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif")
{
$contentType = "image/$ext";
}
else
{
$contentType = "application/octet-stream";
}
return Response::make($imagecontents, 200, array('Content-Type' => $contentType));

Error: "There was a p‌r‌o‌b‌l‌e‌m saving package data" - Magento

I followed this tutorial Package the module which I have developed. Module works fine. When I tried to save I get this error "There was a problem saving package data" as shown in the screenshot too.
Documentation says You will have ”There was a problem saving package data” when you save the extension if there is space inside the module name. But as you can see there is not spaces in the module name.
What could be the issue? How can I fix this?
in linux
change the connect folder permision to
chmod -R 777 /var/www/magento/var/connect/
NOTE: Extensions are case sensitive. Make sure the package name reflects accordingly in all folders and xml files. e.g. MyExtension is not same as Myextension.
NOTE: The package name must NOT have space inside. For example, use Foo_Bar, don’t use “Foo Bar”. You will have ”There was a problem saving package data” when you save the extension if there is space inside the module name.
Capital letters & spaces matter.
Heres another example of adding a group, and then deleting a group.
// Adding attribute options
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "position");
$aClasses = array('Administrator','Dean','Counselor');
$updates = array();
$updates['attribute_id'] = $attribute->getId();
for($cnt = 0; $cnt < sizeof($aClasses); $cnt++) {
$updates['values'][] = $aClasses[$cnt];
}
$setup->addAttributeOption($updates);
die();
// Deleting attribute options
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "position");
//Values have to be deleted one at a time
// Eav Setup.php
$updates = array();
foreach ($attribute->getSource()->getAllOptions() as $option) {
$update['value'] = array();
$update['delete'][$option['value']] = true;
$update['attribute_id'] = $attribute->getId();
$update['value'][$option['value']] = true;
$updates[] = $update;
}
$setup->addAttributeOption($updates);
die();

Resources