Laravel - copy image - laravel

i need to copy an image and save in diferent name. how can i do this in laravel?
Please help me.
img/master.jpg -> copy -> paste with different name (user1)
----now------
img/master.jpg
img/user1.jpg

You can use laravel File helper, here is the file System Doc.
$oldPath = 'images/1.jpg'; // publc/images/1.jpg
$newPath = 'images/2.jpg'; // publc/images/2.jpg
if (\File::copy($oldPath , $newPath)) {
dd("success");
}
if you need to rename it following would be helpful,
$oldPath = 'images/1.jpg'; // publc/images/1.jpg
$fileExtension = \File::extension($oldPath);
$newName = 'new file.'.$fileExtension;
$newPathWithName = 'images/'.$newName;
if (\File::copy($oldPath , $newPathWithName)) {
dd("success");
}

Related

how to use database saved links of image to get images from laravel folder

i have saved images in 'public/images' folder in Laravel and the link/name is saved in mysql database. all i want to get all images via api call. the problem is i can get a single image easily but couldnt get all the images.[[[enter image description here](https://i.stack.imgur.com/9gerk.jpg)](https://i.stack.imgur.com/MIBIk.jpg)](https://i.stack.imgur.com/QcPQm.jpg)
i have no issue with single image however unable to get all at once. thanks
Try this instead
Store the only image name and extension into database and then retrieve it by using DB and use asset to get image, refer the following code as practice.
$custom_data = array();
for ($i = 0; i <= $total_images; $i++) {
$image_name = $data[$i]->image;
if ($image_name != "") {
$image_with_path = asset('public/products/') . '/' . $image_name;
} else {
$image_with_path = "";
}
$custom_data['image'] = $image_with_path;
}

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

Laravel 5.4 Storage : downloading files. File does not exist, but clearly it does

I have been going round and round with this. I have uploads working with the follow:
public function store(Tool $tool)
{
If(Input::hasFile('file')){
$file = Input::file('file');
$name = $file->getClientOriginalName();
$path=Storage::put('public',$file); //Storage::disk('local')->put($name,$file,'public');
$file = new File;
$file->tool_id = $tool->id;
$file->file_name = $name;
$file->path_to_file = $path;
$file->name_on_disk = basename($path);
$file->user_name = \Auth::user()->name;
$file->save();
return back();
}
however when I try to download with:
public function show($filename)
{
$url = Storage::disk('public')->url($filename);
///$file = Storage::disk('public')->get($filename);
return response()->download($url);
}
I get the FileNotFound exception from laravel
However, if I use this instead:
$file = Storage::disk('public')->get($filename);
return response()->download($file);
I get
FileNotFoundException in File.php line 37: The file "use calib;
insert into
notes(tool_id,user_id,note,created_at,updated_at)
VALUES(1,1,'windows server 2008 sucks',now(),now());" does not exist
which is the actual content of the file...
It can obviously find the file. but why wont it download?
Try this:
return response()->download(storage_path("app/public/{$filename}"));
Replace:
$file = Storage::disk('public')->get($filename);
return response()->download($file);
With:
return response()->download(storage_path('app/public/' . $filename));
response()->download() takes a path to a file, not a file content. More information here: https://laravel.com/docs/5.4/responses#file-downloads
If any one still could not find their file even though the file clearly exists then try
return response()->file(storage_path('/app/' . $filename, $headers));
It could be due to a missing directory separator or it isn't stored inside the public folder.

CkFinder - Images from different folder mixed up

I have different folders under CKFinder to store images of different users.
I can also browser them separately without disturbing images of other users.
The problem occurs when two users have images with the same name say "1.png", then one image is shown for both users.
If we have 2.png for userA and 3.png for userB then there is no problem of images mixed up.
In SetConfig function of config.ascx
string folderPhysicalPath = Server.MapPath("~/Uploads/Images/"+MySession.ClientKey);
if (!System.IO.Directory.Exists(folderPhysicalPath))
System.IO.Directory.CreateDirectory(folderPhysicalPath);
// The base URL used to reach files in CKFinder through the browser.
BaseUrl = Convert.ToString(ConfigurationManager.AppSettings["AppPath"]) + "/Uploads/Images/"+MySession.ClientKey+"/";
// The phisical directory in the server where the file will end up. If blank, CKFinder attempts to resolve BaseUrl.
BaseDir = folderPhysicalPath;
.
.
.
.
type = ResourceType.Add("Images");
type.Url = BaseUrl + "/Images/";
type.Dir = BaseDir == "" ? "" : BaseDir + "/Images/";
type.MaxSize = 0;
type.AllowedExtensions = new string[] { "bmp", "gif", "jpeg", "jpg", "png" };
type.DeniedExtensions = new string[] { };
I have changed resourcetype to be dynamic instead of static "Images".
type = ResourceType.Add(MySession.ClientKey + "_Images");
This solved my problem..

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