Reputation: 173
i am trying to move a file with the following code:
$f = 'image.jpeg';
$source ='/Waiting/$f';
$destination = '/Excepted/$f';
copy($source, $destination) or die("Error 1");
However I get this error every time:
Warning: copy(Waiting/$f) [function.copy]: failed to open stream: No such file or directory in C:\xampp\htdocs\gallery\v2\excepted.php on line 13
I realize it is because there is no file but it is not picking up the variables.
Upvotes: 1
Views: 170
Reputation: 2096
try this
$f = 'image.jpeg';
$source = "/Waiting/$f"; // both values are in double quotes
$destination = "/Excepted/$f"; // both values are in double quotes
copy($source, $destination) or die("Error 1");
hope it works
Upvotes: 1
Reputation: 1672
Your code should be:
$f = 'image.jpeg';
$source ='/Waiting/'.$f;
$destination = '/Excepted/'.$f;
copy($source, $destination) or die("Error 1");
This means that you combine string Waiting
and variable $f... This should work...
Hope it helps!
Try using this (since PHP 5.0 Linux or PHP 5.3.1 on Windows):
$f = 'image.jpeg';
$source ='/Waiting/'.$f;
$destination = '/Excepted/'.$f;
rename($source, $destination);
This function should to the job better... It will do all at once (make file on new destination and delete old one)...
Upvotes: 1
Reputation: 24967
because you are using ' instead of "
your code should be
$f = "image.jpeg";
$source ="/Waiting/$f";
$destination = "/Excepted/$f";
copy($source, $destination) or die("Error 1");
' is not working for $variable.
example:
<?php
$f="file";
echo 'myfile: $f';
echo "<br/>";
echo "myfile: $f";
?>
you will see following result
myfile: $f
myfile: file
Upvotes: 2
Reputation: 50009
You need to use double quotes if you want variable parsing to work
$source = "/Waiting/$f";
Upvotes: 1