0

https://trevim.pt/header-4/ I'm copying this image to this link https://trevim.pt/anuncios/header.png

When I run the script it always says 'File copied successfully' but some times I only get the top half of the image... it's not at all a large file (22.6KB), is this behavior normal? How can I copy the whole image every time? Any ideas? Here's my code:

foreach($to_activate as $data_row)
{
    $template_id = $data_row['template_id'];
    $img_url = $data_row['img_url'];
    $template = mysqli_query($conn, "SELECT name FROM `wp_ad_templates` WHERE id = '$template_id' limit 1")->fetch_object()->name;

    $dst = "../" . $template . ".png";

    if(!@copy($img_url, $dst))
    {
        $errors= error_get_last();
        echo "COPY ERROR: ".$errors['type'];
        echo "<br>".$errors['message']."<br><br>";
    } else {
        echo "File copied from remote!";
    }
}

By the way I found this similar question Php copy only copies part of file which is solved by using exec() but that solution didn't work for me, I get:

COPY ERROR: 2 exec() has been disabled for security reasons

  • 3
    When you don't have the `@` to suppress any errors in the `copy` do you get anything useful? – Nigel Ren Jun 19 '20 at 15:26
  • 2
    You could check the file size of the source image and then of the image after it's been copied, and if the sizes are not equal then you know it failed. I know that doesn't help you solve the `copy` problem, but at least you'd be able to better detect a failure. – zeterain Jun 19 '20 at 15:45
  • Please refer the below URL https://www.php.net/manual/en/function.imagecopy.php – Balamurugan M Jun 19 '20 at 15:59
  • I have `ini_set('display_errors', 1); error_reporting(E_ALL);` at the beginning so the @ is there by mistake, it's removed now. – Henrique Saias Jun 19 '20 at 16:04

0 Answers0