简体   繁体   中英

copying a file from a remote server with php copy command

I am trying to copy() a file from a remote server with the copy() command as below:

<?php

    error_reporting(E_ALL);

    $url = $_GET['url'];

    if (copy( $url, '/tmp/copy_from_url.jpeg'))
    {
        echo 'copied';
    }
?>

It seems to work as copied is displayed however there is no file to be found.

Any ideas on how I can track down the problem here?

I am running MAMP on Lion both the latest versions. The file in question is a .jpeg and allow_url_fopen is on.

Edit: the folder Applications/MAMP/tmp is actually a symbolic link to /private/tmp where the files ARE being copied but are not visible.

Is there a way to change PHP tmp folder?

您应该在MAMP设置中将apache和mysql服务器的用户从'www / mysql'更改为'user / user',其中'user'是您的mac os用户-http: //screencast.com/t/wzyPmFTmj6LC

your code should be fine, but i think had better using file_get_contents() and file_put_contents() to more reliable reason, like

<?php
$source = $url;
$destination = '/tmp/copy_from_url.jpeg';

$data = file_get_contents($source);

$handle = fopen($destination, "w");
fwrite($handle, $data);
fclose($handle);
?>

see if that work ?

If these are your permissions ls -l /tmp

lrwxr-xr-x@ 1 root wheel 11 Jul 20 23:44 /tmp -> private/tmp – ian 9 hours 

That looks like ordinary processes don't have write permission then. The last rx means that te other users (not root or wheel group) lack the w write right. Usually Apache runs under a separate accounts, which is why PHP also cannot access it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM