can't find error in file copy script

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
lokanath7
New php-forum User
New php-forum User
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Fri Nov 19, 2010 7:52 am

ur code is fine
the copy() will work on both php 4 nd 5
which version u r using ?

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Fri Nov 19, 2010 10:06 am

take a look at php.net/basename

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Fri Nov 19, 2010 10:29 am

Code: Select all


$URL = 'http://www.leonardo.sk/obrazky/6267.jpg';
$filename = basename($URL);

if (!@copy($URL,$filename))
{
        $errors = error_get_last();
        echo "COPY ERROR: ".$errors['type'];
        echo "<br />\n".$errors['message'];
} else {
        echo "File Copied!";
}

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Mon Nov 22, 2010 11:21 am

Yes, but my script makes for more flexibility.
For example, I can feed any URL into it, and filename becomes the picture that I need, and not statically mapped.

Also, makes the rest of the code less confusing, less to write, less to troublehsoot.

anyway, it was merely a suggestion, you don't have to do anything except breathe. :)

-B

phpmike
New php-forum User
New php-forum User
Posts: 37
Joined: Thu Nov 04, 2010 3:16 pm

Fri Nov 26, 2010 3:57 pm

The reason might be the permissions on the directory as well.

Post Reply