Reputation: 19
In my PHP app, copy()
function works fine, but is not working in server.
$new_file = 'some_new_file';
$old_file = 'existing_file';
if ( copy($new_file, $old_file) ) {
return new JsonResponse(array('status' => true,'success' => 'File saved successfully'));
//print_r("Copy success!");
}else{
return new JsonResponse(array('status' => false,'success' => 'Problem in saving file'));
}
It is returning status as true
, but $old_file
is not updated.
In this even copy() returns true, because the response what I'm getting is
{"status":true,"success":"File saved successfully"}
Upvotes: 0
Views: 497
Reputation: 5146
Looks like you swapped the arguments to copy
around. From the documentation on php.net:
<?php
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
As you can see, the source file is specified first, the destination second.
Specific to your code, try changing
copy($new_file, $old_file)
to
copy($old_file, $new_file)
Upvotes: 2