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
https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/
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.