Jump to content

[SOLVED] any way to speed this up?


justAnoob

Recommended Posts

Is there any way to speed up the upload script??? Or is it the image size that is holding me back?

 

<?php
session_start();
include "connection.php";

$item_name = mysql_real_escape_string($_POST['item_name']);
$description = mysql_real_escape_string($_POST['description']);
$in_return = mysql_real_escape_string($_POST['in_return']);
$category = mysql_real_escape_string($_POST['listmenu']);

define ("MAX_SIZE","1500");
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i)
{
	return "";
}
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
if(isset($_POST['submit']))
{
$image=$_FILES['image']['name'];
if($image) 
{

	$filename = stripslashes($_FILES['image']['name']);

	$extension = getExtension($filename);
	$extension = strtolower($extension);
	if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png"))
	{
		$_SESSION['badformat'] = "Your picture must be a .JPG .GIF or .PNG";
		header("location: http://www.------.com/----.php");
		$errors=1;
		exit();

	}
	else
	{
		$size=filesize($_FILES['image']['tmp_name']);
		if ($size > MAX_SIZE*1024)
		{
			$_SESSION['toobig'] = "Your picture can not exceed 1.5 megabyte.";
			header("location: http://www.-------.com/-----.php");
			$errors=1;
			exit();
		}

		$image_name=time().'.'.$extension;
            $newname="userimages/$category/".$image_name;

		$copied = copy($_FILES['image']['tmp_name'], $newname);
		if (!$copied)
		{
			$_SESSION['notcopy'] = "There was an error posting your picture. Please try again later.";
			header("location: http://www.-----.com/--------.php");
			$errors=1;
			exit();

		}

	}
}
}

// if everything is good, post new item for the user
$mysqlcategory = $category;
$imgpath = $newname;
$findit = $_SESSION['id'];
$result=mysql_query("SELECT id FROM members WHERE username = '$findit'");
$row=mysql_fetch_assoc($result);
$user_id = $row['id'];
$sql = "INSERT INTO abcxyz(item_name, description, in_return, imgpath, category, user_id)VALUES('$item_name','$description','$in_return', '$imgpath', '$mysqlcategory', '$user_id')";
mysql_query($sql) or die(mysql_error());
// go to confirmation page if upload is completed.
if(isset($_POST['submit']) && !$errors)
{
$_SESSION['posted'] = $item_name;
$_SESSION['picposted'] = $imgpath;
header("location: http://www.------.com/-------.php");
exit();
} 

?>

Link to comment
https://forums.phpfreaks.com/topic/161453-solved-any-way-to-speed-this-up/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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