acctman Posted April 27, 2008 Share Posted April 27, 2008 can someone help me clean up this coding. the file extension, convert image and save image sections if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } session_start(); // Check the upload if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) { header("HTTP/1.1 500 Internal Server Error"); echo "invalid upload"; exit(0); } // Get File Extension preg_match('/\.([^\.]+)$/',$_FILES["Filedata"]["tmp_name"],$out); $ext = $out[1]; // Convert Image to .jpg if($ext == "jpg" || $ext == "jpeg" || $ext == "pjpeg") { $image = imagecreatefromjpeg($picture); } elseif($ext == "gif") { $image = imagecreatefromgif($picture); } // Save converted image header ("Content-type : image/jpg"); ImageJpeg($image); ImageJpeg($image, "image.jpg"); // this needs to be $_FILES["Filedata"]["tmp_name"] . jpg ImageDestroy($image); // Get the image and create a thumbnail $img = @imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]); if (!$img) { header("HTTP/1.1 500 Internal Server Error"); echo "could not create image handle"; exit(0); } Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/ Share on other sites More sharing options...
mrdamien Posted April 27, 2008 Share Posted April 27, 2008 can someone help me clean up this coding. the file extension, convert image and save image sections Could you clear that up? What is it you need help with? Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/#findComment-528164 Share on other sites More sharing options...
acctman Posted April 27, 2008 Author Share Posted April 27, 2008 can someone help me clean up this coding. the file extension, convert image and save image sections Could you clear that up? What is it you need help with? the coding for those 3 sections i just copied randomly from the net. so a lot of it doesn't work Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/#findComment-528176 Share on other sites More sharing options...
AndyB Posted April 27, 2008 Share Posted April 27, 2008 the coding for those 3 sections i just copied randomly from the net. so a lot of it doesn't work Yeah, that happens a lot. How about you start over by explaining what you want to do and what results you get from your randomly copied bits of code. This isn't cleaning up, this is called writing a working script. Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/#findComment-528369 Share on other sites More sharing options...
acctman Posted April 27, 2008 Author Share Posted April 27, 2008 the coding for those 3 sections i just copied randomly from the net. so a lot of it doesn't work Yeah, that happens a lot. How about you start over by explaining what you want to do and what results you get from your randomly copied bits of code. This isn't cleaning up, this is called writing a working script. the problem i'm having is, i'm not getting any errors. But, it's not doing what its suppose to do, which is detect if the image is .gif and if it is convert it to .jpg and save the file with the new .jpg extension. is it okay to use $_FILES["Filedata"]["tmp_name"] . jpg for the imagejpeg line at the bottom for saving? <?php // Get the session Id passed from Upload. if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } session_start(); // Check the upload if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) { header("HTTP/1.1 500 Internal Server Error"); echo "invalid upload"; exit(0); } // Get File Extension preg_match('/\.([^\.]+)$/',$_FILES["Filedata"]["tmp_name"],$out); $ext = $out[1]; // Convert Image to .jpg if($ext == "jpg" || $ext == "jpeg" || $ext == "pjpeg") { $image = imagecreatefromjpeg($picture); } elseif($ext == "gif") { $image = imagecreatefromgif($picture); } //Save converted image header ("Content-type : image/jpg"); ImageJpeg($image); ImageJpeg($image, "image.jpg"); ///////////// this needs to be $_FILES["Filedata"]["tmp_name"] . jpg ImageDestroy($image); Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/#findComment-528420 Share on other sites More sharing options...
acctman Posted April 27, 2008 Author Share Posted April 27, 2008 i think the file extension part is working fine, after that comes the detection of for the ext. if its .jpg or .gif. if it gif then it should convert the image. the final part is the saving the image. I definitely know that this is not working . I made a comment next to the save part. I need for the tmp upload name to be saved with a .jpg extension. Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/#findComment-528465 Share on other sites More sharing options...
acctman Posted April 29, 2008 Author Share Posted April 29, 2008 still trying to get this fixed Link to comment https://forums.phpfreaks.com/topic/103105-image-upload-clean-up/#findComment-529736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.