/    Sign up×
Community /Pin to ProfileBookmark

imagejpeg(): Unable to open

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

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 14.2005 — 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.
Copy linkTweet thisAlerts:
@silencer01authorJul 14.2005 — 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!:

[code=php]
<?
$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>&nbsp;</td></tr></table>';

?>[/code]
Copy linkTweet thisAlerts:
@bokehJul 14.2005 — Well first this script does not have 91 lines so it can't be the one causing the problem on lines 91 and 97.
Copy linkTweet thisAlerts:
@silencer01authorJul 14.2005 — 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
Copy linkTweet thisAlerts:
@bokehJul 14.2005 — 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 '[B]Note[/B]: JPEG support is only available if PHP was compiled against GD-1.8 or later.'
Copy linkTweet thisAlerts:
@ZiplineJul 15.2005 — 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.
×

Success!

Help @silencer01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...