Search code examples
phpmamp

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?


Solution

  • 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 r-x 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.