I want a "/" behind "vandiepen" and "test.txt. Now, Laravel gives an error, because it's not a good path to the file.
The file "C:\xampp\htdocs\systeembeheer\storage/download/vandiepentest.txt" does not exist
I tried to put the "/" behind the $folder and the $id variable.
$file = storage_path(). "/download/".$folder "/" .$id;
When I do that, Laravel gives an error:
syntax error, unexpected '"/"' (T_CONSTANT_ENCAPSED_STRING)
The problem is that you missed . (concatenation operator) after $folder.
It should be:
$file = storage_path() . "/download/" . $folder. "/" . $id;
Also you can use DIRECTORY_SEPARATOR.
$file = storage_path() . DIRECTORY_SEPARATOR . "download" . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $id;
Related
I tried to create a new log file if there is a phpmailer error. But the file is not created. I check my directory (777).
Do you have an idea ?
Thank you
if (DEBUG_EMAIL == 'true'){
$this->phpMail->SMTPDebug = $this->debug_level; //2
$this->phpMail->Debugoutput = function($str, $level) {
$filename = CLICSHOPPING::BASE_DIR . 'Work/Log/phpmail_error-' . date('Ymd') . '.log';
$data = date('Y-m-d H:i:s') . "\t" . "\t$level\t$str\n";
$flags = FILE_APPEND | LOCK_EX;
file_put_contents($filename, $data, $flags);
};
// $this->phpMail->SMTPDebug = SMTP::DEBUG_SERVER;
}
Double check all your values, don't assume they are what you think they are. For example what is in CLICSHOPPING::BASE_DIR? Also, it's usual for directory env vars to not have a trailing slash, so you may be missing one when you append Work/... to it. Try this:
$filename = CLICSHOPPING::BASE_DIR . '/Work/Log/phpmail_error-' . date('Ymd') . '.log';
$data = date('Y-m-d H:i:s') . "\t" . "\t$level\t$str\n";
For example:
I have a directory with project.
In that 3 sub directories.
In that 3 sub directories 1 text file in each.
Now I am using scandir() to find how many files& directive present in that project. But scandir() is only scanning 1 level mean it is not scanning sub directories how to scan them also.
If you are using the command line, you can use find and wc.
To count all files recursively:
find . -type f | wc -l
To find directory count:
find . -type d | wc -l
+++++++++++++++++++++++++++++
-type f = file
-type d = directory
wc = prints newline, word or byte count which takes a parameter -l to give you line count
If you are referring to using scandir in PHP, you can try something like this:
<?php
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
$result[] = $value;
}
}
}
return $result;
}
?>
Source: comment #88 http://php.net/manual/en/function.scandir.php
I have a really impossible task for me. I know how put string content in wordpress ( )
but i don't know how put in this code. I want delete call and show text string.
if (!is_page_template('splash.php')) {
echo '<!-- _________________________ Start Custom HTML _________________________ -->' .
'<div class="header_html">' . "\n" .
'<div class="header_html_outer">' . "\n" .
'<div class="header_html_inner">' . "\n";
if ($cmsms_option[CMSMS_SHORTNAME . '_header_custom_html']) {
echo stripslashes($cmsms_option[CMSMS_SHORTNAME . '_header_html']) . "\n";
}
echo '<div class="cl"></div>' .
'</div>' . "\n" .
'</div>' . "\n" .
'</div>' . "\n" .
'<!-- _________________________ Finish Custom HTML _________________________ -->';
}
i can change it with the nexxt code, but show in front : _e( "text i want translate", "comercialdelmotor");
if (!is_page_template('splash.php')) {
echo '<!-- _________________________ Start Custom HTML _________________________ -->' .
'<div class="header_html">' . "\n" .
'<div class="header_html_outer">' . "\n" .
'<div class="header_html_inner">' . "\n" . '_e( "text i want translate", "comercialdelmotor");';
echo '<div class="cl"></div>' .
'</div>' . "\n" .
'</div>' . "\n" .
'</div>' . "\n" .
'<!-- _________________________ Finish Custom HTML _________________________ -->';
}
I hope I understood your question correctly. You are correct in using _e() to echo a string. Your syntax use is wrong though. Never ever use " to enclose a translatable string, the translator does not recognise it, so your string is skipped/ignored.
The correct way is to use '. So your string should look something like this _e( 'string to be translated', 'domainname' ); Note that domainname is optional, so using _e( 'string to be translated' ); is also correct.
You can go and read more about translating your theme in this great tutorial. http://code.tutsplus.com/tutorials/translating-your-theme--wp-25014
Here is my command
for i in `find . -name '*Source*.dat'`; do cp "$i" $INBOUND/$RANDOM.dat; done;
Here are the files (just a sample):
/(12)SA1 (Admitting Diagnosis) --_TA1-1 + TA1-2/Source.dat
./(12)SA1 (Admitting Diagnosis) --_TA1-1 + TA1-2/Source_2000C.dat
./(13)SE1 (External Cause of Injury) --_ TE1-1+TE1-2/Source.dat
./(13)SE1 (External Cause of Injury) --_ TE1-1+TE1-2/Source_2000C.dat
./(13)SE1 (External Cause of Injury) --_ TE1-1+TE1-2/Source_POATest.dat
./(14)SP1(Primary)--_ TP1-1 + TP1-2/Source.dat
./(14)SP1(Primary)--_ TP1-1 + TP1-2/Source_2000C.dat
./(14)SP1(Primary)--_ TP1-1 + TP1-2/Source_ProcDateTest.dat
./(15)SP1(Primary)--_ TP1-1 + TP1-2 - SP2 -- TP2-1 + TP2-2/Source.dat
./(16)SP1(Primary)--_ TP1-1 + TP1-2 +TP1-3- SP2 -- TP2-1 + TP2-2/Source.dat
./(17)SP1(Primary)--_ TP1-1 + TP1-2 +TP1-3/Source.dat
./(18)SP1(Primary)--_ TP1-1 + TP1-2 - SP2 -- TP2-1 + TP2-2 - Copy/Source.dat
./(19)SD1 (Primary)+SD2 (Other Diagnosis)--_ TD12/Source.dat
./(19)SD1 (Primary)+SD2 (Other Diagnosis)--_ TD12/Source_2000C.dat
./(19)SD1 (Primary)+SD2 (Other Diagnosis)--_ TD12/Source_POATest.dat
./(2)SD3--_TD4 SD4--_TD4/Source.dat
./(2)SD3--_TD4 SD4--_TD4/Source2.dat
Those spaces are getting tokenized by bash and this doesn't work.
In addition, I want to append some randomness to the end of these files so they don't collide in the destination directory but that's another story.
find . -name '*Source*.dat' -exec sh -c 'cp "$1" "$2/$RANDOM.dat"' -- {} "$INBOUND" \;
Using -exec to execute commands is whitespace safe. Using sh to execute cp is necessary to get a different $RANDOM for each copy.
If all the files are at the same directory level, as in your example, you don't need find. For example,
for i in */*Source*.dat; do
cp "$i" $INBOUND/$RANDOM.dat
done
will tokenize correctly and will find the correct files provided they are all in directories which are children of the current directory.
As #chepner points out in a comment, if you have bash v4 you can use **:
for i in **/*Source*.dat; do
cp "$i" $INBOUND/$RANDOM.dat
done
which should find exactly the same files as find would, without the tokenizing issue.
How about:
find . -name '*file*' -print0 | xargs -0 -I {} cp {} $INBOUND/{}-$RANDOM.dat
xargs is a handy way of constructing an argument list and passing it to a command.
find -print0 and xargs -0 go together, and are basically an agreement between the two commands about how to terminate arguments. In this case, it means the space won't be interpreted as the end of an argument.
-I {} sets up the {} as an argument placeholder for xargs.
As for randomising the file name to avoid a collision, there are obviously lots of things you could do to generate a random string to attach. The most important part, though, is that you verify that your new file name also does not exist. You might use a loop something like this to attempt that:
$RANDOM=$(date | md5)
filename=$INBOUND/$RANDOM.dat
while [ -e $filename ]; do
$RANDOM=$(date | md5)
filename=$INBOUND/$RANDOM.dat
done
I'm not necessarily advocating for or against generating a random filename with a hash of the current time: the main point is that you want to check for existence of that file first, just in case.
There are several ways of treating files with spaces. You can use findin a pipe, while and read:
find . -name '*Source*.dat' | while read file ; do cp "$file" "$INBOUND/$RANDOM.dat"; done
try something like
while read i;do
echo "file is $i"
cp "$i" $INBOUND/$RANDOM.dat
done < <(find . -name '*Source*.dat')
I have a file called search.txt containing multiple search patterns
example "search.txt" (Over 300 entries in total):
A28
A32
A3C
A46
A50
A5A
898
8A2
8AC
8B6
8C0
Example files from folder I want to search (Over 5000 in total):
1_0_1_4AB_3_56_300000_0_0_0.png
1_0_1_5A0_20_56_300000_0_0_0.png
1_0_1_A28_22_56_300000_0_0_0.png
1_0_1_A32_22_56_300000_0_0_0.png
1_0_1_A96_23_56_300000_0_0_0.png
1_0_1_898_21_56_300000_0_0_0.png
I need to check the fourth string of all .png's against all entries in search.txt (The strings are devided by "_")
I used a perl script similar to this before:
match4th.pl
#!/usr/bin/perl -w
use strict;
my $pat = qr/$ARGV[0]/;
while (<STDIN>) {
my (undef, undef, undef, $fourth) = split /_/;
print if defined($fourth) && $fourth =~ $pat;
}
Then I would use something like this to execute the sccript and move matching files to new location:
cd /png_folder
find . -name '*.png' | perl match4th.pl '/tmp/search.txt' | xargs mv -t /tmp/results
The part I am unsure about is how to tell the find command to use all entries in /tmp/search.txt rather than writing each pattern into the find command
I would also prefer to copy the files rather than move them
You could just use the search.txt file as a list of patterns with grep directly:
find . -name '*.png' | grep -f search.txt | xargs ...
Or if you want to make the patterns more strict, you could do something like this:
find . -name '*.png' | grep -f <(sed s/^/[0-9]_[0-9]_[0-9]_/ search.txt)
Or even more strict with:
find . -name '*.png' | grep -f <(sed s?^?/[0-9]_[0-9]_[0-9]_? search.txt)
And even more strict with:
find . -name '*.png' | grep -f <(sed 's?.*?/[0-9]_[0-9]_[0-9]_&_?' search.txt)
In this last one, an entire line in search.txt is matched (.*), and in the replacement we prefix with the pattern /[0-9]_[0-9]_[0-9]_, followed by the matched string (&), followed by a _. So for example if you have the letter A as a pattern in search.txt, this will generate a pattern for that line as /[0-9]_[0-9]_[0-9]_A_, which will correctly match your file with _A_ there.
If the output looks good, you can pipe it to xargs to copy the matched files like this:
... | xargs -i{} cp {} /path/to/dir
Most efficient solution should be:
use strict;
use warnings;
use File::Basename; # no_chdir will cause we will get full path name
use File::Find;
use File::Copy; # copy and move will work as shell's cp and mv
my ( $fn, $dir, $target ) = #ARGV; # script arguments
# check parameters
( stat($dir) && -d _ ) or die "Not a dir $dir";
( stat($target) && -d _ ) or die "Not a dir $target";
# construct regexp for matching files
# use quotemeta to sanitize data read from $fn file
my $re = join '|', map quotemeta, do {
# open file
open( my $fh, '<', $fn ) or die "$fn: $!";
my #p = <$fh>; # read all patterns
close($fh);
chomp #p; # remove end of line from patterns
#p; # return of do statement
};
$re = qr/$re/; # precompile regexp
# it makes trie for up to ten thousand patterns so match should be O(1)
sub wanted {
my $fourth;
lstat($_) # initialize special _ term
&& (
-d _ # is directory? Return true so step in depth
|| -f _ # otherwise if is file
&& /\.png$/ # is filename in $_ ending .png
# split by '_' to five pieces max and get fourth part (index 3)
&& defined( $fourth = ( split '_', basename($_), 5 )[3] ) # check if defined
&& $fourth =~ /^$re$/ # match regexp
&& do { move( $_, $target ) or die "$_: $!" } # then move using File::Copy::move
); # change move to copy if you want copy file instead
}
# do not change directory so $target can be relative and move will still work well
find( { wanted => \&wanted, no_chdir => 1 }, $dir );
Usage
perl find_and_move.pl /tmp/search.txt . /tmp/results
You use my $pat = qr/$ARGV[0]/;, but $ARGV[0] is /tmp/search.txt. You need to actually read the file.
#!/usr/bin/perl -w
use strict;
my $re = do {
my $qfn = shift(#ARGV);
open(my $fh, '<', $qfn) or die $!;
chomp( my #pats = <$fh> );
my $pat = join '|', map quotemeta, #pats;
qr/^$pat\z/
};
while (<>) {
my $tag = (split /_/)[3];
next if !defined($tag);
print if /$re/;
}