Jump to content

Image resizing.


dlouis95

Recommended Posts

First I would like to say hello because Im new here and new to php.

I would like to take an image I've uploaded and save it as well as a thumbnail in two directory. Can you guys give the MOST basic code out there for this? Ill give the script I have already and the script that's working for me right now. My sites name is http://www.daniellsmith.com.

 

The script I would like to add this code to is this:

<?php

 

// ==============

 

// Configuration

 

// ==============

srand ((double) microtime( )*1000000);

$random_number = rand(0,100000000);

$uploaddir = "uploaded_files";

$uploadFilename=time().'_'.$random_number.".gif";

if (($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg")

or ($_FILES["file"]["type"] == "image/png"))

  {

  if ($_FILES["file"]["error"] > 0)

    {

    die("Error: " . $_FILES["file"]["error"] . "<br />");

    }

  else

    {

    if(is_uploaded_file($_FILES['file']['tmp_name']))

{

move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$uploadFilename);

}

 

    }

  }

else

  {

  die("Invalid file. Only Png Jpg and gif images are allowe to be posted on this site at this time.");

  }

 

$host=""; // Host name

$username=""; // Mysql username

$password=""; // Mysql password

$db_name=""; // Database name

$tbl_name=""; // Table name

 

// Connect to server and select database.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// get data that sent from form

$topic=$_POST['topic'];

$detail=$_POST['detail'];

$name2=$_POST['name2'];

$email=$_POST['email'];

$fileName=$uploadFilename;

$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

$datetime=date("m/d/y"); //create date time

 

if($topic==null)

{

echo die("You did not put the pictures name!");

}

if($name2==null)

{

echo die("You did not put your name!");

}

if($email==null)

{

die("You didnt put your email! To get emails saying that you have gotton a comment, you need to put your real emial address.");

}

$sql="INSERT INTO $tbl_name(topic, detail, name2, email, datetime, file, ip)VALUES('$topic', '$detail', '$name2', '$email', '$datetime', '$fileName', '$ip')";

$result=mysql_query($sql);

 

if($result){

header( 'Location: http://www.daniellsmith.com/index.php' ) ;

}

else {

echo "ERROR";

}

mysql_close();

?>

 

Thanks in advanced if you can help or can't.

Link to comment
https://forums.phpfreaks.com/topic/195619-image-resizing/
Share on other sites

  Quote

What is the script saying when you run it?

 

The script runs fine. I'm just trying to get some additional code so it will resize the image and save it to another directory. Ive tried several different things and have failed each time so I decided to get some personal help.

Link to comment
https://forums.phpfreaks.com/topic/195619-image-resizing/#findComment-1027849
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.