Solved

can't get imagejpeg() to save file.

Posted on 2007-12-03
3
1,023 Views
Last Modified: 2012-06-27
I have a form on http://123fresno.com/crop that collects info where in a picture I want to start cropping and how big the new img should be.

<form name='cropform' action='http://123fresno.com/crop/crop.php' method='POST' target='_blank'>
<input type='hidden' name='imgaddress' value='bigblack.jpg'>
src_x<input type='text' class='xy' name='src_x'> src_y<input type='text' class='xy' name='src_y'><br>
src_w<input type='text' class='xy' name='src_w'> src_h<input type='text' class='xy' name='src_h'><br>
<input type='submit' value='Crop'><input type='reset' value='Clear' onclick='Mclick=3;'>
</form>

The form opens up a new php page with code:
<?php

function cropimage($src_x,$src_y,$src_w,$src_h,$imgaddress){
      $documentroot = $_SERVER['DOCUMENT_ROOT'];
      $dst_im = imagecreatetruecolor ( $src_w, $src_h );
      $src_im = imagecreatefromjpeg($documentroot."/crop/".$imgaddress);
      $dst_x = 0; // 0px to the left on $dst_im
      $dst_y = 0; // 0px to the top on $dst_im
      imagecopy ( $dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h );
      $newimg = "temp.jpg";
      imagejpeg ( $dst_im, $documentroot."/crop/".$newimg );
      echo "<img src='$newimg'>";
}
cropimage($_POST['src_x'],$_POST['src_y'],$_POST['src_w'],$_POST['src_h'],$_POST['imgaddress']);
      
?>

But every time I get the error message:
Warning: imagejpeg() [function.imagejpeg]: Unable to open '/home/fresocom/public_html/crop/temp.jpg' for writing in /home/fresocom/public_html/crop/crop.php on line 11

It does not want to save the image to temp.jpg using the function imagejpeg($dst_im,$documentroot."/crop/".$newimg ); and I cant understand what I am missing.


0
Comment
Question by:kalleanka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 125 total points
ID: 20401886
Hi kalleanka,

maybe you have no write access in '/home/fresocom/public_html/crop/'? To ocheck this you could try to first open that file using 'fopen' with a "w" param ...

BTW, I'm not sure if it's a good idea to hardcode the filename 'temp.jpg' - if i.e. two or more users use that code the 'temp.jpg' for the first user maybe overwritten by the script running for the next user.

Maybe you should call 'tempnam()' to create a unique, writable temp file and retrieve its name - then you can write the JPG into this file.

Hope that helps,

ZOPPO
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 20401919
check the access permission to the folder ... give write permission to the folder / crop

more discussed about this at, http://in2.php.net/function.imagejpeg
0
 
LVL 1

Author Closing Comment

by:kalleanka
ID: 31412538
totally forgot about setting the folder to writable. thanks. I was tearing my hair :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question