AdSpace Posted November 2, 2012 Share Posted November 2, 2012 Hello all forum members: I am new here and I need help! I have a file that let the user upload a file to our server/script it should resize and save the file to our server folder, but the final file saved is 0 bytes I do have ImageMagik 6.8.0-4 installed on the server hosting I will post the file code below for review Thanks in advance to all ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <?php session_start(); session_register("sess_data"); include("engine.php"); //security check! are we logged in? if ($sess_name != ""){ // OK to continue \\ //Standard includes\\ secheader(); echo ("<br />"); bannerads(); echo ("<br />"); echo ("<a href='../members/index.php'><font size='4'><b>Return To Member Home</b></font></a><br /><br /"); if ($_SERVER['REQUEST_METHOD'] == "POST") { $uploaddir = "../splash_engine/photo/"; //step 1 get the file and see if it is a jpg\\ //*== get file extension (fn at bottom of script) ==*/ /*== checks to see if image file, if not do not allow upload ==*/ $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg")) { echo ("<h3>"); print "ERROR - Image Extension Unknown.<br>"; print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>"; echo ("<br />"); echo ("</h3>"); echo $testmessage; echo ("<br />"); tads(); secfooter(); /*== delete uploaded file ==*/ unlink($imgfile); exit(); } //step 2 resize it\\ //-- RE-SIZING UPLOADED IMAGE /*== get size of image ==*/ if (filesize($imgfile) > 56600 || filesize($imgfile) < 2) { $imgsize = GetImageSize($imgfile); $width = $imgsize[0]; $height = $imgsize[1]; echo ("<br>"); echo $width; echo (" Width"); echo ("<br>"); echo $height; echo (" height"); echo ("<br>"); echo $filename . ': ' . filesize($imgfile) . ' bytes'; echo ("<br>"); error_level(); } else { $tmpimg = "temp".$ref.".jpg"; /*== RESIZE PROCESS 1. decompress jpeg image to pnm file (a raw image type) 2. scale pnm image 3. compress pnm file to jpeg image ==*/ /*== Step 1: djpeg decompresses jpeg to pnm ==*/ system("djpeg $imgfile >$tmpimg"); /*== Steps 2&3: scale image using pnmscale and then pipe into cjpeg to output jpeg file ==*/ system("pnmscale -xy 75 100 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); /*== remove temp image ==*/ unlink($tmpimg); } //step3 define the file name\\ $newfile = $ref.".jpg"; $final_filename = $newfile; $upload=$filepaths.$newfile; //echo $upload." - filename"; // make sure resize has worked!\\ //animated gifs renamed will crash it!\\ if (filesize($imgfile) ==0 ){ echo ("<br>"); error_level(); } //step 4 - copy it over to server. if (!copy($imgfile, $upload)) { //email admin\\ //$file = '../splash_engine/photo/'.$ref.'.jpg'; if (file_exists($upload)) { } else { /*== if an error occurs the file could not be written, read or possibly does not exist ==*/ error_level(); } } //mail variables\\ $mailto = $adminmail ; $email = $sess_name; $name = "member ID ".$ref; $subject = $ref." Member Photo uploaded"; $yourname = $testmessage ; $formurl = $memberimage ; $messageproper = "This message was sent from:\n". "$yourname\n". "---------------------- $name ---------------\n\n" . "The image uploaded was $formurl\n". "If this breaks your rules, remove it with the Admin member photo tool.\n". "Otherwise no action is needed.\n". "\n\n----------------------------------------------------------------------\n" ; mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" $email>\nX-Mailer: POSH Splash Engine Version 1.1" ); /*== delete the temporary uploaded file ==*/ unlink($imgfile); } ?> </head> <body bgcolor="#FFFFFF"> <h2>Upload Your Image</h2> <br><?php images()?><br> <p><strong>Warning misuse of this facility will result in immediate termination of your account.</strong><br> <br> These include, but are not limited to: </p> <ul> <li>Any images of an inappropriate nature.</li> <li>Racist symbolism.</li> <li>Any file that is copyrighted or any copyright logos.<br> </li> </ul> <p align="center"><strong>Please note we only accept images of H100 x W75 pixels in JPG format.<br> </strong><strong>Larger images will be automatically resized, it is your responsibilty to ensure that your image will appear correctly if resized. </strong></p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="500000"> <p>Upload Image: <input type="file" name="imgfile"><br> <font size="1">Click browse to upload a local file</font><br> <br> <input type="submit" value="Upload Image"> </form> <?php echo ("<br />"); echo $testmessage; echo ("<br />"); tads(); secfooter(); // end the main function for logge in users// } else { // log them them smart arses out! echo("<meta HTTP-EQUIV='REFRESH' content='2; url=$self_url'>"); echo("<h2><b><center>Invalid User! - Error 3</h2></b></center><br>"); http_redirect ($self_url); exit; } ?> <?php /*== FUNCTIONS ==*/ function getFileExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext;} function error_level() { echo ("<h3>"); echo ("The file size is too big to be resized. Please try again with a smaller image"); echo ("<br />"); echo ("OR it was a not a true JPEG. <br>Please try again with a smaller file in the correct format."); echo ("<br />"); echo ("</h3>"); echo $testmessage; echo ("<br />"); tads(); secfooter(); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
JohnTipperton Posted November 3, 2012 Share Posted November 3, 2012 do you save the file in ftp or database? Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted November 3, 2012 Share Posted November 3, 2012 do you save the file in ftp or database? Web server user uploads the image, but anyways... It looks like what you are trying to do is relying on system commands, couldn't you utilize any PHP based methods of image manipulation? I mean it is using getimagesize(); so that indicates to me that the GD library is installed, unless the function is declared in another PHP file. I never used ImageMagick so I might not be much help on that end. GD is pretty easy though and can be written out in a few lines, imagecreate() create new resized image getimagesize() but you already have that one imagecreatefromjpeg() open the uploaded jpeg file imagecopyresampled() there is a lot of arguments to assign to this one: (new image, source image, src_x, _y, dest_x, _y [so these would be 0 for this use], new_w, new_h, old_w, old_h) imagejpeg() Quote Link to comment 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.