2

I get the following error when writing a thumbnail image to the below directory

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'D:\imagesdb\images\62t\' for    writing: No such file or directory

if I manually create a directory and then add that to imagejpeg() for example: C:\images I get the same error, this also applies if I use fopen

Warning: fopen(C:\images\) [function.fopen]: failed to open stream: No such file or directory

All paths exsist! I have also checked the varibles to see if the paths are correct and I am not loosing data, (var_dump!)

I have also tried chmod, but I am using windows and this should not apply?

I am using

Windows XP Home Edition SP3 running localhost, XAMMP, apache, php

I am worried if it the OS version I am using, I have tried giving the apache service local system account access in 'services', tried sharing the folder!

I can write a normal images on upload to another folder 'images\62' in the same dirctory, however 'images\62t' either has permission denied, or does not exist when I try and write a thumb?

I have checked php.ini, gd is enabled and I have tried un-commenting: extension=php_gd2.dll , safe-mode is also off.

I am worried if it is my OS version, it's very limited where file permissions are concerned? Or is it just my code?

if($this->changed){
    //$tp = fopen("C:\images\\",'w+');
    chmod($this->thumb_path, 0777);
    $originalImage = imagecreatefromjpeg($this->image_path);
    $width = imagesx($originalImage);
    $height = imagesy($originalImage);

    $thumb_width = $this->thumbWidth;
    $thumb_height = floor($height * ($this->thumbWidth / $width));
    $newImage = imagecreatetruecolor($thumb_width,$thumb_height);
    imagecopyresized($newImage,$originalImage, 0, 0, 0, 0, $thumb_width, $thumb_height,  $width, $height );
    imagejpeg($newImage,$this->thumb_path);

} else {
           $this->_messages[] = $field['name' ] . 'did not upload please check and try again' ;
}
TimWolla
  • 31,849
  • 8
  • 63
  • 96
Alan
  • 279
  • 1
  • 8
  • 19

3 Answers3

6

$this->thumb_path probably only contains a path without a filename. Without a filename: How should PHP know how to name the file?

TimWolla
  • 31,849
  • 8
  • 63
  • 96
  • ah! newImage is the name of the new file $this->thumb_path is where it is written to? – Alan Feb 13 '12 at 21:06
  • Nope. `$newImage` is the image-resource. `$this->thumb_path` has to contain the Qualified-Path (Folder + Filename) – TimWolla Feb 13 '12 at 21:13
  • I'v added $imgs = $this->thumb_path . $this->fname; and var_dump the result which is correct file name "D:\imagesdb\images\62t\default_17.jpg" imagejpeg($newImage,$this->$imgs); However result is now Notice: Undefined property: Image_Upload::$D:\imagesdb\images\62t\default_18.jpg which is line imagejpeg($newImage,$this->$imgs); Thanks for your help – Alan Feb 13 '12 at 21:22
  • Oh I've just seen the errors of my ways! removed $this-> from $imgs! Thanks for your help TimWolla problem solved – Alan Feb 13 '12 at 21:25
3

try to put the relative path instead of putting the absolute path in imagejpeg, at least that's how I resolve that problem.

cyber cyber1621
  • 167
  • 2
  • 6
1

$image_path=getcwd()."/your_images_directory/yourfile.jpg";

chmod your directory to 775 or whatever feeds your requirements.

This stack have suggestions for the permissions

Community
  • 1
  • 1
CesareoAguirre
  • 1,557
  • 13
  • 11