Reputation: 329
I have a file I'm attempting to move and Im able to do so, however I can't seem to change the filename exactly how I need it.
$file1 = "/../../../../../../rooms.GENRE.FILENAME/FILENAMEentry.html";
$newfile1 = "/../../../../creative/$path/ $dir entry.html";
copy($file1, $newfile1);
$dir
is the variable with the name of the file I'm calling.
this returns the file name as FILENAME entry.html
and I need the space between them removed.
I've tried it without the space as in
$direntry.html
and that moves and creates the file but just names it .html
Basically I'm replacing where it says FILENAMEentry.html
(the capitalized portion) with the name of the filename in $dir
Upvotes: 0
Views: 160
Reputation: 3114
You should check out these string operators.
This should work fine:
$file1 = "/../../../../../../rooms.GENRE.FILENAME/FILENAMEentry.html";
$newfile1 = "/../../../../creative/$path/".$dir."entry.html";
if (!copy($file1, $newfile1)) {
echo "failed to copy file.";
}
Stephen Clay
<?php "{$str1}{$str2}{$str3}"; // one concat = fast $str1. $str2. $str3; // two concats = slow ?>
Use double quotes to concat more than two strings instead of multiple '.' operators. PHP is forced to re-concatenate with every '.' operator.
Upvotes: 1
Reputation: 12391
Actually $dir works while echoing but you have space and if you write them together the word would be $direntry
which will be ambiguous for the interpreter so use concatenation.
change
$newfile1 = "/../../../../creative/$path/ $dir entry.html";
to
$newfile1 = "/../../../../creative/$path/".$dir."entry.html";
Upvotes: 1
Reputation: 742
Did you try with:
$newfile1 = "/../../../../creative/$path/{$dir}entry.html";
Upvotes: 0
Reputation: 14123
Consider using concatenation:
$newfile1 = "/../../../../creative/$path/" . $dir . 'entry.html';
Upvotes: 3