By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

imagejpeg() unable to write to file: "is a directory"

Markus
Expert 5K+
P: 6,050
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error:
Expand|Select|Wrap|Line Numbers
  1. Warning: imagejpeg() [function.imagejpeg]: Unable to open '../uploads/thumb/' for writing: Is a directory in /home/.gobbles/mahcuz/mahcuz.com/upload/uploaded.php on line 129
And this is some of the code from the page:
Expand|Select|Wrap|Line Numbers
  1. /* New code for thumbnails. Will on work if user selects "create thumb on upload" on the upload page */
  2.     //check to see if checkbox is selected
  3.     if(isset($_POST['thumbBox'])){
  4.     // Load image and get image size
  5.         $img1 = "../uploads/mahcuz_".$uploadedImg;
  6.         $orgimg = imagecreatefromjpeg($img1);
  7.         $width = imagesx($orgimg);
  8.         $height = imagesy($orgimg);
  9.         // Setting new width and height for thumbnail size
  10.         $newwidth = 100; //any size as you wish
  11.         $newheight = floor($height*($newwidth/$width));
  12.         // Creating new temporary image
  13.         $tmpimg = imagecreatetruecolor($newwidth, $newheight);
  14.         // Copy and resize old image into new image
  15.         imagecopyresized($tmpimg, $orgimg, 0, 0, 0, 0, $newwidth, $newheight, $width, $height );
  16.         // Save thumbnail into a file
  17.         $path = "../uploads/thumb/"; // <<<< this is line 129 !
  18.         imagejpeg($tmpimg, $path.$img) or die("error");
  19.         $thumbAlert = "Thumbnail created succesfully. Please use the code provided (on the right) to link to the 
  20.  
  21. thumbnail of your uploaded image";
  22.     }
  23.  
  24. /* end code for thumbnails */
  25.  
The created thumbnails are intended to be saved in a directory - root - uploads/thumb/

Not sure what the problem might be. It says unable to write, could it be the file permissions? I've got it set to 777

Thanks :)
Oct 13 '07 #1
Share this Question
Share on Google+
6 Replies


ak1dnar
Expert 100+
P: 1,584
Problem is with the second parameter for this function.
Expand|Select|Wrap|Line Numbers
  1. imagejpeg($tmpimg, $path.$img)
You have to set the path correctly.
Oct 13 '07 #2

Markus
Expert 5K+
P: 6,050
Problem is with the second parameter for this function.
Expand|Select|Wrap|Line Numbers
  1. imagejpeg($tmpimg, $path.$img)
You have to set the path correctly.
I'm not sure it is, i have the exact same coding on a test i have on my locahost (computer xampp thing) and it works just fine >_>
Oct 13 '07 #3

pbmods
Expert 5K+
P: 5,821
Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Oct 13 '07 #4

ak1dnar
Expert 100+
P: 1,584
As error describes you can't write down your thumbnail to a directory ilke this;
../what_ever_dir/
It should be a new image path like;
../what_ever_dir/new_thumb_location.jpg

And what about "$img" and "$img1" variables on your scripts. do they suppose to contain the same values or do they having different values. because I didn't see any value for $img variable, yet.
Oct 13 '07 #5

Markus
Expert 5K+
P: 6,050
As error describes you can't write down your thumbnail to a directory ilke this;
../what_ever_dir/
It should be a new image path like;
../what_ever_dir/new_thumb_location.jpg

And what about "$img" and "$img1" variables on your scripts. do they suppose to contain the same values or do they having different values. because I didn't see any value for $img variable, yet.
Awesome! What i was doing was on the right tracks but i'd forgotten to change the name of the variable when i'd copied it from my other file :D

Thanks a bunch

Expand|Select|Wrap|Line Numbers
  1. $path.$img /* which would join the path and img name to create thumb/img.jpg was supposed to be /*
  2. $path.$uploadedImg // as $uploadedImg is the correct variable :D
  3.  
Oct 13 '07 #6

ak1dnar
Expert 100+
P: 1,584
You are welcome ! Postback anytime. Good luck...
Oct 13 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.