iamtom Posted October 21, 2007 Share Posted October 21, 2007 Linux, Apache, PHP 4.4.7 Both scripts work fine independently I have two scripts, first one uploads data to a flatfile data database, including an image file reference and the actual image file. My problem is that I can't expect my users to resize their images, properly or consistantly. Many images are 600K to 1meg. I have another script that resizes images as they are loaded, allowing the user to upload any size image at 400x325 or whatever I set the parameters at. I know 400 x 325 is usually still over 200K but its a lot samller than the 600K I'm getting now. I then 'read' the datafile and display the info in html tables. The overall purpose is to creat a flatfile database for a second hand store, allowing 'customers' to see the items for sell, store is for active duty troops on a militray base. . Here is the code, I don't mean to create any issues so I will leave the fist line and the last two lines off so they don't appear actiive, and I have also xxxx'd out the domain. My idea is the have the second script included in the first script so that the image will be reized on fly as it is uploaded. Any help would be appreciated,,, this store is primarly used by lower rank troops, with less income. (1st script) include("global.inc.php"); $errors=0; $error="The following errors occured while processing your form input.<ul>"; pt_register('POST','DateRcvd'); pt_register('POST','status'); pt_register('POST','mgrName'); pt_register('POST','ItemDescr2'); pt_register('POST','ItemDescr'); pt_register('POST','Kcondition'); pt_register('POST','Kcomments'); pt_register('POST','Property'); pt_register('POST','Lot'); pt_register('POST','Value'); pt_register('POST','FMValue'); pt_register('POST','Quantity'); pt_register('POST','Fund'); pt_register('POST','Activity'); pt_register('POST','CostCtr'); pt_register('POST','Spare'); $Photo=$HTTP_POST_FILES['Photo']; pt_register('POST','ID'); if($HTTP_POST_FILES['Photo']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['Photo']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['Photo']['name'].", was not uploaded!"; $errors=1; } $DateRcvd = date("Y-m-d"); $ID = date("ymds"); $Lot = date("yd"); if($errors==1) echo $error; else{ $image_part = date("mds")."_".$HTTP_POST_FILES['Photo']['name']; $image_list[12] = $image_part; copy($HTTP_POST_FILES['Photo']['tmp_name'], "autoimages/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); $message="DateRcvd: ".$DateRcvd." mgrName: ".$mgrName." ItemDescr: ".$ItemDescr." Kcondition: ".$Kcondition." Kcomments: ".$Kcomments." Property: ".$Property." Value: ".$Value." FMValue: ".$FMValue." Quantity: ".$Quantity." Fund: ".$Fund." Activity: ".$Activity." CostCtr: ".$CostCtr." Photo: ".$where_form_is."www.xxxxxxxx.com/IA/NEISO/autoimages/".$image_list[12]." ID: ".$ID." "; $message2= "Items requested for approval to sell at NAF Resale Store, click here for a Listing http://www.xxxxxxx.com/cgi-bin/NEISA.pl?status=Hold "; $message2 = stripslashes($message2); $message = stripslashes($message); mail("xxxxxxx.xxxxxx@xxxxxxxx.af.mil","Request to Approve NAF Resale Items",$message2,"From: WebSite"); mail("xxxxxxxxxxxx.xxxx@xxxxxxx.af.mil","(Copy)Request to Approve NAF Resale Items",$message,"From: WebSite"); $make=fopen("NEISOdata.dat","a"); $to_put=""; $to_put .= "|".$DateRcvd."|".$status."|".$mgrName."|".$ItemDescr."|".$ItemDescr2."|".$Kcondition."|".$Kcomments."|".$Property."|".$Lot."|".$Value."|".$FMValue."|".$Quantity."|".$Fund."|".$Activity."|".$CostCtr."|".$image_list[12]."|".$ID."|".$Spare."|" "; fwrite($make,$to_put); ?> <!-- This is the content of the Thank you page, be careful while changing it --> <h2>Thank you!</h2> To add additional items from same cost center, <INPUT TYPE=BUTTON ONCLICK='history.back()' VALUE=' Return to the previous page '> and change the appropriate info , then click Add Item. Now for the second script, resizes images as they are uploaded. // This is the temporary file created by PHP $uploadedfile = $_FILES['uploadfile']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 400 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 400, simply change the $newwidth variable $newwidth=400; $newheight=325; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = "images/". $_FILES['uploadfile']['name']; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. Quote Link to comment https://forums.phpfreaks.com/topic/74241-combining-two-scripts/ Share on other sites More sharing options...
trq Posted October 21, 2007 Share Posted October 21, 2007 Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/74241-combining-two-scripts/#findComment-375044 Share on other sites More sharing options...
iamtom Posted October 21, 2007 Author Share Posted October 21, 2007 Yes, my question is how to make the two scripts work like one, so the image can be resized as it is loaded along with all the other required information... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/74241-combining-two-scripts/#findComment-375046 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.