Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

I have put together a Community Partners page with a backend that allows you to add the text plus upload an image of your business card. It is functioning as is. But, I want to reorganize so all the images go into /images/partners

Right now it goes to the root. I borrowed this code from somewhere else, so I don't know where to define the upload location.

 

Anyone can help?

 

View online

 

<?php
/*
 $Id: conditions.php,v 1.22 2003/06/05 23:26:22 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');



 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_CONDITIONS));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<?php

if ($_SERVER['REQUEST_METHOD'] == "POST")
{

/* SUBMITTED INFORMATION - use what you need
 * temporary filename (pointer): $imgfile
 * original filename		   : $imgfile_name
 * size of uploaded file	   : $imgfile_size
 * mime-type of uploaded file  : $imgfile_type
 */

 /*== upload directory where the file will be stored 
	  relative to where script is run ==*/

$uploaddir = ".";


/*== 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"))
{
	print "<h1>ERROR</h1>Image Extension Unknown.<br>";
	print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>";
	print "The file you uploaded had the following extension: $pext</p>\n";

	/*== delete uploaded file ==*/
	unlink($imgfile);
	exit();
}


//-- RE-SIZING UPLOADED IMAGE

/*== only resize if the image is larger than 250 x 200 ==*/
$imgsize = GetImageSize($imgfile);

/*== check size  0=width, 1=height ==*/
if (($imgsize[0] > 250) || ($imgsize[1] > 250)) 
{
	/*== temp image file -- use "tempnam()" to generate the temp
		 file name. This is done so if multiple people access the 
		script at once they won't ruin each other's temp file ==*/
	$tmpimg = tempnam("/tmp", "MKUP");

	/*== 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 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");

	/*== remove temp image ==*/
	unlink($tmpimg);
   //print "Error Uploading File - Too large.";
   //   exit();

}

/*== setup final file location and name ==*/
/*== change spaces to underscores in filename  ==*/
$final_filename = str_replace(" ", "_", $imgfile_name);
$newfile = $uploaddir . "/$final_filename";

/*== do extra security check to prevent malicious abuse==*/
if (is_uploaded_file($imgfile))
{

   /*== move file to proper directory ==*/
   if (!copy($imgfile,"$newfile")) 
   {
	  /*== if an error occurs the file could not
		   be written, read or possibly does not exist ==*/
	  print "Error Uploading File.";
	  exit();
   }
 }

/*== delete the temporary uploaded file ==*/
unlink($imgfile);


print("<img src=\"$final_filename\">");

/*== DO WHATEVER ELSE YOU WANT
	 SUCH AS INSERT DATA INTO A DATABASE  ==*/

}
?>
<!-- header_eof //-->

<!-- body //-->

<!-- Start code -->
<tr><td valign="top">
   <table border="0" cellspacing="0" cellpadding="0">
		<tr><td width="212" valign="top"><?php require(DIR_WS_INCLUDES . 'column_left.php'); ?></td>
			<td width="4"></td> 					
			<td width="502" valign="top">

				<table border="0" cellspacing="0" cellpadding="0">
				  <tr><td height="2" bgcolor="#919191" width="502"></td></tr>
				  <tr><td height="28" bgcolor="#003471" width="490" style="padding-left:22px;"><span class="tx2">Community Partners</span></td></tr>
				</table>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr><td class="smallText_11">

	<table cellpadding="0" cellspacing="0" border="0" width="100%">

  <tr>
	<td class="main">

	<?



# connect to database
  $cid = mysql_connect(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}


?>
<table width="100%"  border="1" cellpadding="5">
 <tr bgcolor="#336699">
<td align="center"><a href=partners.php>View Partners</a></td>
<td align="center"><a href=insert_partner.php>Add Partners</a></td>
<td align="center"><a href=manage.php>Edit Partners</a></td>
<td align="center"><a href=upload.php>Upload Image</a></td>
</tr>
</table>	
**Note**<br>
<span class="style1"><font color="#CC0033">Image MUST be no more than 250x250px and MUST be a jpeg or jpg file. <br>
If upload error occurs, use BACK button to try again.</font></span>
<form action="<?php echo $_SERVER['community/PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">

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

</body>
</html>

<?php
/*== FUNCTIONS ==*/

function getFileExtension($str) {

	$i = strrpos($str,".");
	if (!$i) { return ""; }

	$l = strlen($str) - $i;
	$ext = substr($str,$i+1,$l);

	return $ext;

}
?>


	</td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>
  <tr>
	<td><table border="0" width="100%" cellspacing="1" cellpadding="2">
	  <tr>
		<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
		  <tr>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
			<td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
			<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
</table>

<!-- body_eof //-->

</td></tr>
</table>
<!-- body_eof //-->
<!-- End code -->
		</td>
	 </tr>	
	</table> 			 			 		
 </td></tr>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Posted

In case you folks are scared to help because of a full page of code, here is the part that I believe needs changing. But since I don't know what the . means in this context, I don't know what to change it to.

 

 

/*== upload directory where the file will be stored 
	  relative to where script is run ==*/

$uploaddir = ".";

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...