I want to move all images up 1 folder after which I can remove the empty folder but I always get the error "File already exists at path: public/images"
$files = Storage::files('public/images/'.$dir->name);
foreach($files as $file){
Storage::move($file, 'public/images');
}
Storage::deleteDirectory('public/images/'.$dir->name);
$dir->delete();
The files that I wanted to remove don't exist in the public/images directory. So why do I get the error "File already exists at path: public/images"?
This should solve your problem.
$files = Storage::files('public/images/'.$dir->name);
foreach($files as $file){
Storage::move($file, 'public/images/'.basename($file));
}
Storage::deleteDirectory('public/images/'.$dir->name);
$dir->delete();
Related
I'm attempting to use the perl script below to create symlinks of all folders from three locations. My desired result would be something like:
Source
/TV720/GoT/Season00/
/TV1080/GoT/Season01/
/TV2160/GoT/Season02/
Destination (Symlink)
/TV/GoT/Season00/
/TV/GoT/Season01/
/TV/GoT/Season02/
However when I run the script, I get: /TV/GoT/Season00/ without the other folders found in other sources.
It appears the 2nd and 3rd source location sub-folders aren't symlinked and merged in the event of duplicate folder names.
#!/usr/bin/perl
use strict;
use warnings;
my #sourceList = (
"/Volumes/Disk/TV720",
"/Volumes/Disk/TV1080",
"/Volumes/Disk/TV2160",
);
my $destinationFolder = "/Volumes/Disk/TV";
foreach my $currentSource (#sourceList) {
opendir SDIR, $currentSource or do {
warn "$0: can't opendir $currentSource: $!\n";
next;
};
my #sourceFolders = grep { not /^\.{1,2}$/ } readdir SDIR;
closedir SDIR;
foreach my $currentFolder (sort #sourceFolders) {
my $fromPath = $currentSource . '/' . $currentFolder;
my $toPath = $destinationFolder . '/' . $currentFolder;
if (not -e $toPath) {
# print "Creating $toPath as symlink to $fromPath\n";
symlink $fromPath, $toPath
or warn "$0: can't symlink $toPath to $fromPath: $!\n";
}
}
}
Given the information above, you might be able to accomplish what you want with union mounts on the file system. This is where you can overlay directories on top of other directories. It's more advanced than a symlink for sure, but it might do what you want.
If you want to continue with the symlinks, I would suggest modifying your script to loop through your sources and recursively iterate the subfolders in each directory.
Then for each subfolder, create an actual new folder in the destination, then iterate the files in the source subfolder and symlink each file individually.
$cellDirectory = storage_path() . '/app/public/uploads/images/' . $cell->user_id . '/' . $cell->id;
if (is_dir($cellDirectory)) {
$success = File::deleteDirectory($cellDirectory);
}
$success is true, but directory and files didn’t actually delete.
Files in directory have chmod 644
Directory chmod 755
also strange, as the folder was created in this way:
if (!is_dir($path)) {
File::makeDirectory($path, 0777, true);
}
ask for help, thanks
In Linux you cannot delete a non-empty dir unless you specify the argument "-r" (recursive), perhaps it follows the same logic and you have look up the right way to delete a non-empty dir in laravel.
I am trying to upload a video file with my controller as below
Controller
if(Request::hasFile('file1')){
echo "Yes, file";
exit;
$file = Request::file('file1');
$filename = $file->getClientOriginalName();
$path = public_path().'/uploads/';
return $file->move($path, $filename);
} else {
echo "No file";
exit;
}
When i submit my a JPG/PNG file, it echo "Yes, file" i.e the file exist but when i submit an MP4 video, the file isn't found..
What could be the issue please ? Is there a particular way of sending Mp4 to my server in Laravel ?
The issue here can be your php configuration in php.ini regarding the max allowed size of the uploaded file.
post_max_size
upload_max_filesize
I'm just barely familiar with bash scripts, and am trying to achieve being able to specify a source location (a directory with files / sub-directories) and a list of multiple destination directories, along with a list of files / directories from the source to exclude when copying & replacing.
The script should loop through each destination location, copy the files from the source and replace them in the destination location, excluding any files / directories listed in the script to skip.
In PHP it would be something like:
$source = '/home/user1/public_html';
$destinations = array(
'user2',
'user3',
'user4'
);
$exclude = array(
'/uploads/custom',
'/config/conf.php'
);
foreach ($destinations as $destination) {
$dir = '/home/' .$destination. '/public_html';
if (is_dir($dir)) {
exec('cp -R ' .$source. '/* ' .$dir);
// and somehow exclude overwriting any files / directories matching what's in the $exclude array
}
}
So, my question is, how would a bash script with similar functionality be written?
Here's how I ended up doing it:
#!/bin/bash
while IFS= read -r line || [[ $line ]]; do
if [[ -d "$line" ]]; then
rsync -rv --exclude-from "exclude.txt" /home/source/public_html/ "$line"
else
echo "Directory $line does not exist!"
fi
done < "accounts.txt"
This reads from a file called "accounts.txt" that has all the destination account directories in it, one per line. Ex:
/home/user1/public_html
/home/myblog/public_html
It loops through each one, and if the directory exists, it copies the files from /home/source/public_html to the destination. It also reads from a file called "exclude.txt" that includes, one per line, any files or directories to exclude. Ex:
.git
/uploads/custom
/config/conf.php
I am facing a small problem.I need the absolute path of Mage.php file in app folder.
I am using /pinktaff.u1163.cartikahosting.com/app/Mage.php in wordpress plugin "mage enabler"
but it is showing invalid..Can anyyou please help me out.
More than likely /pinktaff.u1163.cartikahosting.com is not the full path to your document root
In magento create a blank php file in the site root and add the code below
<?php echo $_SERVER['DOCUMENT_ROOT']; ? >
See http://www.seomad.com/SEOBlog/find-out-the-root-path-on-your-server-in-php.html
Or
dirname(__FILE__)
see http://php.net/manual/en/function.dirname.php
You could also test to see if the path is correct by doing
<?php
$filename = '/pinktaff.u1163.cartikahosting.com/app/Mage.php';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>