hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : can someone give a little bit of help
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

can someone give a little bit of help

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-19-2006, 12:24 PM
jprice1542 jprice1542 is offline
Newbie
 
Join Date: Sep 2004
Posts: 11

can someone give a little bit of help


I am trying to get this image uploader for a web forum that I help out with. The code wasn't designed by me. The problem with the code is that it should allow a user to upload 12 files then check each file to make sure they are "each" under 500kb, but the script checks all 12 files together and if the user uploads 1 file that is 450kb and 1 that is 200kb it doesn't work. It doesn't even show the correct error message it is programmed to. I am still learning php and I am lost with this can someone please help me.

Also the script is set up to run along side vBulletin, and if they are a member of a certain user group they get the 500kb upload and a different watermark if they are a member of another usergroup they get.

Thanks for the help

Code:
<?
$uploadboxes = 12;

$uploadpath = "uploadfiles/";
$watermarkopacity = 75;
$limitedext = array(".gif",".jpg",".jpeg",".GIF",".JPG",".JPEG");


$databasename = "xxxxxxxx";
$dbuser = "xxxxxxxxx";
$dbpass = "xxxxxxxx";
$conn = mysql_connect("localhost", $dbuser, $dbpass);
mysql_select_db($databasename,$conn);

$ui = $_POST[userid];
if($_POST[sb]) { $sb = $_POST[sb]; }

$sizelimit = 350000;
//if($sb) $sizelimit = 500000;
if($sb) $sizelimit = 500000;

?>
<html>
<head>
<title>Lazy**** Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.headpeice {
	background-image: url(images/misc/forum_header.gif);
	background-repeat: no-repeat;
	background-position: right top;
}
.vbmenu_control2
{
	background: url(images/misc/bgb.gif) repeat-x top left;
	color: #CCCCCC;
	font: bold 11px verdana;
	padding: 0px 10px 0px 0px;
}
.top {
	background-color: #262626;
	font-weight: bold;
}
.left {
	background-color: #4F4F4F;
}
.right {
	background-color: #464646;
}
body {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
td {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
a {
	color: #8EA7D2;
	text-decoration: none;
}
a:hover {
	color: #8EA7D2;
	text-decoration: underline;
}
-->
</style>
<style type="text/css">
<!--
.textbox {
	font-size: 10px;
	color: #CCCCCC;
	background-color: #333333;
	font-family: Arial, Helvetica, sans-serif;
}
-->
</style>
</head>

<body onLoad="start();" bgcolor="#646464" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- logo -->
<a name="top"></a> 
<table height="150" cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<td class="headpeice">&nbsp;</td>
</tr>
</table>
<table height="45" cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
  <tr>
    <td class="vbmenu_control2"><a href="http://www.lazy****.net/store.php"src="images/misc/store1.gif" border="0" alt="Store" /></a> 
     </td>
    <td class="vbmenu_control2" width="100%" align="right"><a href="http://www.lazy****.net"><img src="images/misc/lazylogo.gif" border="0" /></a> 
      </td>
    </tr>
</table>
<br>
<table width="500" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#333333" style="border: 1px solid #AAAAAA">
<tr> 
    <td><a href="upload.php?ui=<? echo $_POST[userid]; if($sb) echo "&sb=".$sb; ?>"><strong>Upload More</strong></a> 
      <strong>- <a href="viewuploads.php?ui=<? echo $ui; if($sb) echo "&sb=".$sb; ?>">View Uploads</a> 
      <? if($sb) { ?>- <a href="viewuploads.php?ui=<? echo $ui; if($sb) echo "&sb=".$sb."&v=1"; ?>">My Pictures</a><? } ?> </strong> 
<p><br>
        <?
for($x=0;$x<$uploadboxes;$x++){
		$file_name = $_FILES['uploadFile'. $x]['name'];
		$file_size = $_FILES['uploadFile'. $x]['size'];
		// strip file_name of slashes
		$file_name = stripslashes($file_name);
		$file_name = str_replace("'","",$file_name);
		$file_name = str_replace(" ", "", $file_name); // Gets rid of spaces.
		$file_name = str_replace("%20", "", $file_name);
		
		$ext = strrchr($file_name,'.'); // Gets file extension.
		
		while ((file_exists($uploadpath.$file_name)) && $file_name) {
			$fileexplode = explode(".",$file_name);
			$file_name = $fileexplode[0]."_.".$fileexplode[1];
		}
        if ($file_size > $sizelimit) {
		
        echo $file_name; ?>
        - ERROR: This file exceeds the size limit of <? echo $sizelimit / 1000; ?>.<br>
        <?
		} elseif (!in_array($ext,$limitedext) && $file_name) {
		echo $file_name; ?>
        - ERROR: The file must be a GIF, JPG or JPEG.<br>
        <?

		} else {
			if($file_name) {	
				$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$uploadpath.$file_name) or die("<br><br><b>There was a permissions problem with uploading. Please contact the site administrator.</b>");
			}
			// check if successfully copied
			if($copy && $file_name){
				// chmod($uploadpath.$locationselect.$file_name, 0777);  // octal; correct value of mode

				if($ext == ".jpg" || $ext == ".jpeg" || $ext == ".JPG" || $ext == ".JPEG") { 
				// Watermarking process if the file is a JPEG.

				$baseimage = ImageCreateFromJpeg($uploadpath.$file_name);
				if($sb) { $logoImage = ImageCreateFromGif("watermark_og.gif"); } 
				else {
				$logoImage = ImageCreateFromGif("watermark.gif");
				}
				$ix = imagesx($baseimage) - imagesx($logoImage);
				$iy = imagesy($baseimage) - imagesy($logoImage);
         
				ImageCopyMerge($baseimage,$logoImage,$ix,$iy,0,0,imagesx($logoImage),imagesy($logoImage),$watermarkopacity);

				//header ("Content-type: image/gif");
				ImageJpeg($baseimage, $uploadpath.$file_name);
				}// Ends watermarking process 
				if(!$_POST[private]) { $setprivate = 0; }
				if($_POST[private] == 1) { $setprivate = 1; }
				$sql = "INSERT INTO imgstorage (userid, image_name, timeup, private) VALUES ('".$_POST[userid]."', '".$file_name."', '".time()."', '".$setprivate."')";
				$result = mysql_query($sql,$conn);
				
				
				$fileurl[$x] = "http://www.lazy****.net/".$uploadpath.$file_name;
				echo $file_name; ?>
        - Uploaded.<br>
        <?

			} /* If $copy */ else{
				if($file_name) {
					echo "$file_name could not be uploaded!<br>";
				}
			} 
		} 
	} // end of loop 
?>
      </p>
      <textarea name="textarea" cols="80" rows="5" class="textbox"><?
	  for($x=0;$x<$uploadboxes;$x++){
	  if($fileurl[$x] != "") {
	  echo "[IMG]".$fileurl[$x]."[/IMG]\n";
	  }
	  }
	  ?></textarea></td>
  </tr>
</table>
<br>
<? for($x=0;$x<$uploadboxes;$x++){
if($fileurl[$x] != "") {
$ext = strrchr($fileurl[$x],'/');
$ext = str_replace("/","",$ext);
 ?>
<table width="500" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#333333" style="border: 1px solid #AAAAAA">
  <tr>
    <td><strong><? echo $ext; ?></strong> 
<hr size="1">
	<img src="<? echo $fileurl[$x]; ?>"></td>
  </tr>
</table><br>
<? }
} ?>

__________________
jprice1542 [at] gmail. com

Reply With Quote


Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
Why Giving a Damn Consistently is Important Blog 2013-01-15 14:45:56
NTCA Fall Conference 2012 Web Hosting Events 2012-08-07 17:06:35
Hosting.com Rounds Out Monitoring Suite with Application Performance Monitoring Web Hosting News 2012-02-08 16:04:10
Cloud Host VPS.NET Launches Beta of Desktop-like Control Panel Web Hosting News 2011-12-07 16:17:52
Web Host HostDime Launches Affiliate Program Web Hosting News 2011-07-13 18:28:33


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?