Click to See Complete Forum and Search --> : imagejpeg(): Unable to open
silencer01
07-14-2005, 02:16 AM
Hi guys,
I'm having problems with imagejpeg(), the error message i'm getting is
imagejpeg(): Unable to open 'image.jpg' for writing in /home/httpd/vhosts/test.php on line 91
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/test.php:91) in /home/httpd/vhosts/test/image_add.php on line 97
is this a server permission issue?
Thanks,
Jake
bokeh
07-14-2005, 06:17 AM
You are trying to send header information to the browser. This must be done before any other content or whitespace. For more info post your script.
silencer01
07-14-2005, 09:17 AM
Here is what i have, the reason for me thinking that it was a permissions problem was because it works fine on our other domain!:
<?
$file= $_FILES['file']['tmp_name'];
$file_name=$_FILES['file']['name'];
$thankspage="image_loaded.htm?lc=".$_POST['lc']."&file=".$_POST['newname'];
$limit_width=$_POST['w'];
$limit_height=$_POST['h'];
$newname=$_POST['newname'];
$uploaddir=$_POST['folder'];
$limit_ext = "yes"; //do you want to limit the extensions of files uploaded
$ext_count = "2"; //total number of extensions in array below
$extensions = array(".jpg", ".jpeg");
$intestazione='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
$intestazione.='<html><head><title>CMS - Image loader</title>';
$intestazione.='<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
$intestazione.='<style type="text/css"><!--';
$intestazione.='.browseField {font-family: verdana;font-size: 11pt;size: 42;color: #333333}';
$intestazione.='.submit {font-family: verdana;font-size: 10pt;color: #333333}';
$intestazione.='.testo {font-family: verdana;font-size: 8pt;}';
$intestazione.='a:link {color: #09608D;}';
$intestazione.='a:hover {text-decoration: none;}';
$intestazione.='a:active {text-decoration: none;}';
$intestazione.='--></style></head>';
$intestazione.='<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bgcolor="#FFFFFF">';
$intestazione.='<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center">';
// Check to see if valid file
if ($file == "none") {
// if no valid file entered, display no file message
echo $intestazione."<span class='testo'>You <b>must</b> specify a file to upload. <a href=javascript:history.back(-1)>Return to the form</a>.</span>";
} else {
$ext = strtolower(strrchr($file_name,'.'));
if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
//$endresult = "<font size=\"2\">File is wrong type</font>";
echo $intestazione."<span class='testo'>File is wrong type. <a href=javascript:history.back(-1)>Return to the form</a>.</span>";
}else{
list($width, $height) = getimagesize($file);
if($width>$limit_width || ($limit_height!="0" && $height>$limit_height)){
if($limit_height=="0"){
$newrap=$width/$height;
$limit_height=$limit_width/$newrap;
}else{
$newrap=$limit_width/$limit_height;
}
//header('Content-type: image/jpeg');
$rap=$width/$height; // 1.33
if($rap>$newrap){
$refheight=$height;
$refwidth=$height/$newrap;
}else{
$refwidth=$width;
$refheight=$width/$newrap;
}
$dx=($refwidth-$width)/2;
$dy=($refheight-$height)/2;
// Load
$thumb = imagecreatetruecolor($limit_width, $limit_height);
$source = imagecreatefromjpeg($file);
// Resize
imagecopyresized($thumb, $source, 0, 0, -$dx, -$dy, $limit_width, $limit_height, $refwidth, $refheight);
// Output
imagejpeg($thumb, $uploaddir.$newname);
}else{
//echo $intestazione."<span class='testo'>Folder:".$uploaddir."</span>";
copy($file, $uploaddir.$newname);
unlink($file);
}
Header("Location: $thankspage");
}
}
echo '<br> </td></tr></table>';
?>
bokeh
07-14-2005, 10:38 AM
Well first this script does not have 91 lines so it can't be the one causing the problem on lines 91 and 97.
silencer01
07-14-2005, 12:05 PM
Sorry, i should have noted that i have taken out alot of irrelavent code comment for clarity.
line 91 is: imagejpeg($thumb, $uploaddir.$newname);
line 97 is: Header("Location: $thankspage");
hope that helps, sorry about the confusion.
Jake
bokeh
07-14-2005, 01:33 PM
The header warning is being cause because you are trying to send that header to the browser after prior output and that prior output is the warning on line 91 so we can forget about the second warning.
I can't see a cause for the first warning but the manual says 'Note: JPEG support is only available if PHP was compiled against GD-1.8 or later.'
Zipline
07-15-2005, 07:51 AM
I noticed you have the error:
imagejpeg(): Unable to open 'image.jpg' for writing in /home/httpd/vhosts/test.php on line 91
When I have used imagejpeg() in the past I had a similar problem. I resolved this problem by changing the permissions on the file and the upload directory to 777.