Jump to content

[SOLVED] Image Upload, size, save new image


iamtom

Recommended Posts

This is kinda a second post,,,,

  My question is , how do I get the two peices of code below to work as one script?

 

    I am rather new to PHP and have been trying to figure out how to upload data and an image,  then resize the image and save as a new image with the same piece of code.

 

    I can do it with multiple scripts, but I have been able to get the scripts intergrated to where I only use one script.    I use  Linux, Apache, and PHP 4.47.  Both peices of code work individually.

 

 

///<?php

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);

?>

 

<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 and save a new image.

 

////<?php

$uploadedfile = $_FILES['uploadfile']['tmp_name'];

$src = imagecreatefromjpeg($uploadedfile);

list($width,$height)=getimagesize($uploadedfile);

$newwidth=400;

$newheight=325;

$tmp=imagecreatetruecolor($newwidth,$newheight);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

$filename = "images/s". $_FILES['uploadfile']['name'];

imagejpeg($tmp,$filename,100);

imagedestroy($src);

imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request

?>

 

Thnaks to anyone that came show me how to make this one script.....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.