Jump to content

Upload image and resize


emvy03

Recommended Posts

Hi,

I've got an upload script which works fine; it checks for image extension and uploads perfectly. The only thing is, I want to add an image resize section of code in there as I have an image gallery which displays the pictures and they are rather large.

 

The code at present


<link rel="stylesheet" href="upload.css" type="text/css"  />
<?php

define ("MAX_SIZE","100"); 


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 it is not empty
	if ($image) 
	{

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

  		$extension = getExtension($filename);
		$extension = strtolower($extension);

if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
		{
	//print error message
			echo '<h1>Unknown extension!</h1>';
			$errors=1;
		}
		else
		{

$size=filesize($_FILES['image']['tmp_name']);


if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}


$image_name=time().'.'.$extension;

$gallery_name = $_POST['galleryselect'];
$newname="../gallery/$gallery_name/".$image_name;

$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}


if(isset($_POST['Submit']) && !$errors) 
{
	echo "<h1>File Uploaded Successfully! Try again!</h1>";
}


include "../storescripts/connect_to_mysql.php";

$sql = mysql_query("INSERT into images (image_path, gallery_name) VALUES ('$newname',$gallery_name')");

?>

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.