Asked  8 Months ago    Answers:  5   Viewed   38 times

I have the following code:

$file = '';
$newfile = '/img/submitted/yoyo.jpg';

if ( copy($file, $newfile) ) {
    echo "Copy success!";
echo "Copy failed.";

and it always output "Copy failed"

copy(/img/submitted/yoyo.jpg) [function.copy]: failed to open stream: No such file or directory

my directory is set to 777.

any ideas? thanks!



While copy() will accept a URL as the source argument, it may be having issues a url for the destination.

Have you tried specifying the full filesystem path to the output file? I'm assuming you're not trying to put the new file onto a remote server.

For example:

$file = '';
$newfile = $_SERVER['DOCUMENT_ROOT'] . '/img/submitted/yoyo.jpg';

if ( copy($file, $newfile) ) {
    echo "Copy success!";
    echo "Copy failed.";

The above worked nicely for me.

Wednesday, March 31, 2021
answered 8 Months ago

If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:

copy('', '/tmp/file.jpeg');

This will take care of any pipelining etc. that's needed. If you need to provide some HTTP parameters there is a third 'stream context' parameter you can provide.

Wednesday, March 31, 2021
answered 8 Months ago

I'd guess that you are on windows and that you have I: mapped to a share such as \server2files ...

If so, that's your problem. These mappings are only avaialble to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\serversharefolderfile.ext', also remember that the IUSR account will need access to these shares/folders/files

Friday, May 28, 2021
answered 5 Months ago

To program ftp from a batch file, see You need to call ftp like this

ftp -i -s:ftpcommands.txt

where ftpcommands.txt looks something like this:

cd out
mget *
del *

For running this every 15 minutes, see other replies (at or Command Scheduler).

(The -i parameter is to turn off interactive prompting - the other way to do this is to add a prompt off command to the commands text file before the mget. Without this, mget will stop and ask you to confirm before getting each file. [Thanks to Adriano for pointing this out!])

Saturday, July 3, 2021
answered 4 Months ago

This should do it.

function chunked_copy($from, $to) {
    # 1 meg at a time, you can adjust this.
    $buffer_size = 1048576; 
    $ret = 0;
    $fin = fopen($from, "rb");
    $fout = fopen($to, "w");
    while(!feof($fin)) {
        $ret += fwrite($fout, fread($fin, $buffer_size));
    return $ret; # return number of bytes written
Thursday, July 29, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :