arrr_matey
arrr_matey

Reputation: 167

Warning: imagejpeg() [function.imagejpeg]: Unable to open [filename] for writing: No such file or directory

I can't figure out why I'm receiving this error when trying to save an image using imagejpeg()

Below is an excerpt from my code where I've eliminated anything extraneous and kept enough to generate the error. The path definitely exists and it has permissions set to 777.

$url = "http://website.com";
    $filename = 'imagename';

    $filepath = $url."/Images/accents/generated/".$filename.".jpg";

    $base = imagecreatefromjpeg($url.'/images/'.$filename);
    $imagewidth = imagesx($base);
    $imageheight = imagesy($base);

    $new = imagecreatetruecolor($imagewidth, $imageheight);

    imagecopy($new, $base, 0, 0, 0, 0, $imagewidth, $imageheight);

    imagejpeg($new, $filepath);

    imagedestroy($new);

`

Upvotes: 1

Views: 7254

Answers (1)

Steven
Steven

Reputation: 6148

This is likely because you're trying to output to a url as opposed to a local document...

Your ouput path:

http://website.com/Images/accents/generated/imagename.jpg

This won't work... The output has to be local, try something like:

./Images/accents/generated/imagename.jpg

Upvotes: 4

Related Questions