Solved

can't get imagejpeg() to save file.

Posted on 2007-12-03
3
1,019 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 32
form button worked now it doesnt anymore 9 41
Session timeout 5 13
echo time from sql to input type="time" 9 17
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now