I got a problem and cant seem to come up with any solutions, appologies if this is in the wrong place.
The code im using below uploads an image to my server and changes the name of that upload to something random, so whoever uploads an image makes it highly unlikly they will overwrite something already in the folder.
However, i cant seem to find any solution to resizing that image to about 600 x 450 pixels, i dont need any thumbnails or any other things, just resize the image to 600 x 450 pixel, this saving space on my server.
The user inputs the details in an html form.
Code: Select all
[color=#0000FF]<form enctype="multipart/form-data" action="http://www.mywebspace.co.uk/add2.php" method="POST">
Name:
<input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>[/color]
Code: Select all
<?php
$ran = rand () ;
$ran2 = $ran.".";
//This is the directory where images will be saved
$target = "photopics/";
$target = $target . $ran2 . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic= $ran2 . ($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("serverip", "username", "password") or die(mysql_error()) ;
mysql_select_db("databasename") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
but can someone please help me on resizing that image, would like to keep the above code just dont know where to add the extra code.
Many thanks
Simon