Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

can't get imagejpeg() to save file.

Posted on 2007-12-03
3
Medium Priority
?
1,026 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses

636 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