winnard2008 Posted July 9, 2008 Share Posted July 9, 2008 Hi Following a recent server change our sites have gone nuts. Errors galore caused by changing from PHP4.3 to PHP5.2 The following error messages are caused when we try to upload an image using a form in one of our clients admin pages. Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/jardinec/public_html/admin/addportfolio.php on line 41 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/jardinec/public_html/admin/addportfolio.php on line 42 Warning: Cannot modify header information - headers already sent by (output started at /home/jardinec/public_html/admin/addportfolio.php:41) in /home/jardinec/public_html/admin/addportfolio.php on line 144 Does anybody know what exactly these messages mean? I am rushing to leave work now, so if code is needed I will try and get it uploaded tomorrow. In the meantime has anybody encountered these messages or know how to fix them? Cheers Danny Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/ Share on other sites More sharing options...
cooldude832 Posted July 9, 2008 Share Posted July 9, 2008 odds are you have written code (or most likely since you clueless on basic errors had code written for you) in OOP that is strict to php4 and doesn't translate cleanly to php5. OR you have a registered_global change between server A and B Check your PHP.ini is similar for this server or verify the OOP is consistent for php5. Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-585491 Share on other sites More sharing options...
craygo Posted July 9, 2008 Share Posted July 9, 2008 may want to check and make sure the new server has GD installed on it. That will give you the 2 image errors. The header error could be because of the 2 errors. You will get that error if anything is outputted to the browser first, in this case it is the 2 errors which would not be there if the function worked correctly. Ray Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-585507 Share on other sites More sharing options...
cooldude832 Posted July 9, 2008 Share Posted July 9, 2008 may want to check and make sure the new server has GD installed on it. Wrong! If GD isn't installed you get a call to undefined function when attempting to use items in the GD library which you state might not exist. Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-585515 Share on other sites More sharing options...
winnard2008 Posted July 9, 2008 Author Share Posted July 9, 2008 At first the GDlibrary wasn't installed and it simply was outputting "NO GD" in place of any images that should have been appearing. We had the GD lib installed yesterday and since then most images have worked fine. With this form it is outputting the image fine. But even so these errors appear. The programmer who created these pages created them when we were on the old server using PHP4.3 and there were no errors and everything was working fine. When I return to work tomorrow I will find the relevant code from the pages and upload them, hopefully this will shed some more light on what is causing the errors. Cheers for the initial help. One more thing, is OOP like programming standards similar to W3C standards in web design??? Or is it something completely different? Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-585632 Share on other sites More sharing options...
cooldude832 Posted July 9, 2008 Share Posted July 9, 2008 OOP is far from standard its object oriented programing and its sorta a big thing in php now a days. A lot of high end applications are written in OOP for their muscle and flexibility, however OOP was added to php in the php 4.1+ versions and major updates have been done between 4-5 that makes some OOP not cross completely. PHP 5 OOP most likely fails in PHP 4. Odds are there is a config like registered_globals() turned off or an error reporting level turned up. Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-585648 Share on other sites More sharing options...
winnard2008 Posted July 10, 2008 Author Share Posted July 10, 2008 As we stand we are still awaiting confirmation of whether the register_globals() is turned on on our server. So having looked at the code for the problems I can see that I think the code uses register_globals() alot in the code. Here is the code for the two pages. Basically the only problem is with the image uploading part of the code. The rest of the form works fine. This page is called addportfolio.php. This is where are client uses a form to create their portfolio, allowing them to upload images, description etc etc. <?PHP include('../xxx/xxxxxx.php'); //Connection to the database. //check if form submitted if(isset($_POST['Submit'])){ if(!get_magic_quotes_gpc()){ $jobtitle = addslashes($_POST['jobtitle']); $customer = addslashes($_POST['customer']); $location = addslashes($_POST['location']); $info = addslashes($_POST['info']); $testimonial = addslashes($_POST['testimonial']); }else{ $jobtitle = $_POST['jobtitle']; $customer = $_POST['customer']; $location = $_POST['location']; $info = $_POST['info']; $testimonial = $_POST['testimonial']; }//end of else $insert = mysql_query("Insert Into portfolio (jobtitle, customer, location, info, testimonial) values ('$jobtitle','$customer','$location', '$info', '$testimonial')"); $id = mysql_insert_id(); $allowed = array ('image/gif','image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/x-png'); if (in_array($_FILES['image1']['type'], $allowed)) { copy ($_FILES['image1']['tmp_name'], "../portfolio/".$_FILES['image1']['name']) or die ("Could not copy"); $getimagesize = getimagesize("../portfolio/".$_FILES['image1']['name']); if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG){//if cmyk jpg rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".jpg"); $image = "portfolioimage1".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_JPEG){//if rgb jpg rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".jpg"); $image = "portfolioimage1".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_GIF){//if GIF rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".gif"); $image = "portfolioimage1".$id.".gif"; $im = @imagecreatefromgif($image); imagegif($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_PNG){//if PNG rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".png"); $image = "portfolioimage1".$id.".png"; $im = @imagecreatefrompng($image); imagepng($im, $image, 75); imagedestroy($im); } //update database with image $query = "Update portfolio Set image1 = '$image' Where id = '$id'"; $result = mysql_query($query); }//end of if image is valid format if (in_array($_FILES['image2']['type'], $allowed)) { copy ($_FILES['image2']['tmp_name'], "../portfolio/".$_FILES['image2']['name']) or die ("Could not copy"); $getimagesize = getimagesize("../portfolio/".$_FILES['image2']['name']); if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG){//if cmyk jpg rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".jpg"); $image = "portfolioimage2".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_JPEG){//if rgb jpg rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".jpg"); $image = "portfolioimage2".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_GIF){//if GIF rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".gif"); $image = "portfolioimage2".$id.".gif"; $im = @imagecreatefromgif($image); imagegif($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_PNG){//if PNG rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".png"); $image = "portfolioimage2".$id.".png"; $im = @imagecreatefrompng($image); imagepng($im, $image, 75); imagedestroy($im); } //update database with image $query = "Update portfolio Set image2 = '$image' Where id = '$id'"; $result = mysql_query($query); }//end of if image is valid format if (in_array($_FILES['image3']['type'], $allowed)) { copy ($_FILES['image3']['tmp_name'], "../portfolio/".$_FILES['image3']['name']) or die ("Could not copy"); $getimagesize = getimagesize("../portfolio/".$_FILES['image3']['name']); if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG){//if cmyk jpg rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".jpg"); $image = "portfolioimage3".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_JPEG){//if rgb jpg rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".jpg"); $image = "portfolioimage3".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_GIF){//if GIF rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".gif"); $image = "portfolioimage3".$id.".gif"; $im = @imagecreatefromgif($image); imagegif($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_PNG){//if PNG rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".png"); $image = "portfolioimage3".$id.".png"; $im = @imagecreatefrompng($image); imagepng($im, $image, 75); imagedestroy($im); } //update database with image $query = "Update portfolio Set image3 = '$image' Where id = '$id'"; $result = mysql_query($query); }//end of if image is valid format //send browser back to edit item header("Location: index.html"); }//end of if form submitted ?> <link href="styles.css" rel="stylesheet" type="text/css" /> <p>Add Portfolio Entry</p> <p>To add a new entry to the portfolio, simply complete the following form and when finished click Submit button. </p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="portfolio" id="portfolio"> <p>Job Title: <input name="jobtitle" id="jobtitle" /> <br /> <br /> Customer: <input name="customer" id="customer" /> <br /> <br /> Location: <input name="location" id="location" /> </p> <p>Job Info:<br /> <textarea name="info" cols="60" rows="10" id="info"></textarea> <br /> <br /> Testimonial<br /> <textarea name="testimonial" cols="60" rows="10"></textarea> <br /> <br /> Image 1: <input name="image1" type="file" id="image1" /> <br /> <br /> Image 2: <input name="image2" type="file" id="image2" /> <br /> <br /> Image 3: <input name="image3" type="file" id="image3" /> <br /> <br /> <input type="submit" name="Submit" value="Submit" /> </p> </form> The form works when you don't upload an image. And does upload and show the image anyway. But brings up the errors at the top of the page. This page is the editportfolio page. Where by they can change there entry, and also upload extra images if they so wish. this again uploads the images so you can see them, but brings up the image errors at the top of this thread. <?PHP include('../xxxx/xxxxxx.xxx.php'); //Connection to the database. //check if Update form submitted if(isset($_POST['id'])){ if(!get_magic_quotes_gpc()){ $id = addslashes($_POST['id']); $jobtitle = addslashes($_POST['jobtitle']); $customer = addslashes($_POST['customer']); $location = addslashes($_POST['location']); $info = addslashes($_POST['info']); $testimonial = addslashes($_POST['testimonial']); }else{ $id = $_POST['id']; $jobtitle = $_POST['jobtitle']; $customer = $_POST['customer']; $location = $_POST['location']; $info = $_POST['info']; $testimonial = $_POST['testimonial']; }//end of else $insert = mysql_query("Update portfolio Set jobtitle = '$jobtitle', customer = '$customer', location = '$location', info = '$info', testimonial = '$testimonial' Where id = '$id' Limit 1"); $allowed = array ('image/gif','image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/x-png'); if (in_array($_FILES['image1']['type'], $allowed)) { copy ($_FILES['image1']['tmp_name'], "../portfolio/".$_FILES['image1']['name']) or die ("Could not copy"); $getimagesize = getimagesize("../portfolio/".$_FILES['image1']['name']); if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG){//if cmyk jpg rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".jpg"); $image = "portfolioimage1".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_JPEG){//if rgb jpg rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".jpg"); $image = "portfolioimage1".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_GIF){//if GIF rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".gif"); $image = "portfolioimage1".$id.".gif"; $im = @imagecreatefromgif($image); imagegif($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_PNG){//if PNG rename("../portfolio/".$_FILES['image1']['name'], "../portfolio/portfolioimage1".$id.".png"); $image = "portfolioimage1".$id.".png"; $im = @imagecreatefrompng($image); imagepng($im, $image, 75); imagedestroy($im); } //update database with image $query = "Update portfolio Set image1 = '$image' Where id = '$id'"; $result = mysql_query($query); }//end of if image is valid format if (in_array($_FILES['image2']['type'], $allowed)) { copy ($_FILES['image2']['tmp_name'], "../portfolio/".$_FILES['image2']['name']) or die ("Could not copy"); $getimagesize = getimagesize("../portfolio/".$_FILES['image2']['name']); if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG){//if cmyk jpg rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".jpg"); $image = "portfolioimage2".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_JPEG){//if rgb jpg rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".jpg"); $image = "portfolioimage2".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_GIF){//if GIF rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".gif"); $image = "portfolioimage2".$id.".gif"; $im = @imagecreatefromgif($image); imagegif($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_PNG){//if PNG rename("../portfolio/".$_FILES['image2']['name'], "../portfolio/portfolioimage2".$id.".png"); $image = "portfolioimage2".$id.".png"; $im = @imagecreatefrompng($image); imagepng($im, $image, 75); imagedestroy($im); } //update database with image $query = "Update portfolio Set image2 = '$image' Where id = '$id'"; $result = mysql_query($query); }//end of if image is valid format if (in_array($_FILES['image3']['type'], $allowed)) { copy ($_FILES['image3']['tmp_name'], "../portfolio/".$_FILES['image3']['name']) or die ("Could not copy"); $getimagesize = getimagesize("../portfolio/".$_FILES['image3']['name']); if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG){//if cmyk jpg rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".jpg"); $image = "portfolioimage3".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_JPEG){//if rgb jpg rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".jpg"); $image = "portfolioimage3".$id.".jpg"; $im = @imagecreatefromjpeg($image); imagejpeg($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_GIF){//if GIF rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".gif"); $image = "portfolioimage3".$id.".gif"; $im = @imagecreatefromgif($image); imagegif($im, $image, 75); imagedestroy($im); }else if ($getimagesize[2] == IMAGETYPE_PNG){//if PNG rename("../portfolio/".$_FILES['image3']['name'], "../portfolio/portfolioimage3".$id.".png"); $image = "portfolioimage3".$id.".png"; $im = @imagecreatefrompng($image); imagepng($im, $image, 75); imagedestroy($im); } //update database with image $query = "Update portfolio Set image3 = '$image' Where id = '$id'"; $result = mysql_query($query); }//end of if image is valid format //send browser back to edit item header("Location: viewportfolio.php"); }//end of if form submitted //otherwise get id of entry $id = $_GET['id']; $query = mysql_query("Select * from portfolio where id = '$id' Limit 1"); while($row = mysql_fetch_array($query)){ //get data from database $jobtitle = $row['jobtitle']; $customer = $row['customer']; $location = $row['location']; $info = $row['info']; $testimonial = $row['testimonial']; $image1 = $row['image1']; $image2 = $row['image2']; $image3 = $row['image3']; }//end of wile loop ?> <link href="styles.css" rel="stylesheet" type="text/css" /> <p>Edit Portfolio Entry</p> <p>To edit the portfolio entry, simply complete the following form and when finished click Update button. </p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="portfolio" id="portfolio"> <p>Job Title: <input name="jobtitle" id="jobtitle" value="<?PHP echo $jobtitle; ?>" /> <br /> <br /> Customer: <input name="customer" id="customer" value="<?PHP echo $customer; ?>" /> <br /> <br /> Location: <input name="location" id="location" value="<?PHP echo $location; ?>"/> </p> <p>Job Info:<br /> <textarea name="info" cols="50" rows="10" id="info" wrap="off"><?PHP echo $info; ?></textarea> <br /> <br /> Testimonial<br /> <textarea name="testimonial" cols="50" rows="10" wrap="off"><?PHP echo $testimonial; ?></textarea> <br /> <br /> </p> <?PHP if($image1 != ''){ ?> <img src="http://www.jardineconservatories.co.uk/php/phpThumb.php?src=http://www.jardineconservatories.co.uk/portfolio/<?PHP echo $image1; ?>&w=200&h=200"><br /> To change this image use the box below <?PHP } ?> <p>Image 1: <input name="image1" type="file" id="image1" /> </p> <p> <?PHP if($image2 != ''){ ?> <img src="http://www.jardineconservatories.co.uk/php/phpThumb.php?src=http://www.jardineconservatories.co.uk/portfolio/<?PHP echo $image2; ?>&w=200&h=200"><br /> To change this image use the box below <?PHP } ?> </p> <p> Image 2: <input name="image2" type="file" id="image2" /> </p> <p> <?PHP if($image3 != ''){ ?> <img src="http://www.jardineconservatories.co.uk/php/phpThumb.php?src=http://www.jardineconservatories.co.uk/portfolio/<?PHP echo $image3; ?>&w=200&h=200"><br /> To change this image use the box below <?PHP } ?> <br /> <br /> Image 3: <input name="image3" type="file" id="image3" /> <br /> <br /> <input name="Update" type="submit" id="Update" value="Update" /> <input name="id" type="hidden" id="id" value="<?PHP echo $id; ?>" /> </p> </form> If this problem is down to the register_globals() issue, could I change to super globals and then it would work? If so which part would i need to change. Thanks, i look forward to somebody saving my bacon. Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-586180 Share on other sites More sharing options...
winnard2008 Posted July 10, 2008 Author Share Posted July 10, 2008 The error seemed to be in the imagedestroy area of the code, I have added the @ to this and got the server guy to downgrade the error reporting. And it seemed to have done the job so this in now solved. Unless anybody fancies looking at the script and notices anything else then please let me know. Cheers for all your help. I have one more issue to post on this forum regarding mod re-write, which is the last issue for our site. Cheers Danny Quote Link to comment https://forums.phpfreaks.com/topic/113934-solved-php-thumb-issues/#findComment-586205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.