I want to just put image locations into the Database. here are the fields of my table.
id
name
img_location
thumb_location
orientation
I know how to send those to such places, but i really dont get how to work with files really. I want to resize any file down to <250kb and also make a thumb of the image. How would i do that? right now, if the file is over 500KB i just reject it, but i am sure i could manipulate it down to 250k or atleast change the dimensions and Qual. any ideas? Someone please help me, i am puting this database together for my fiance's parents and am not charging them, but i want them to be able to interact with it via HTML, because they are not very tech savvy.
//HERE IS MY CODE
<?
// CONFIG
$serverpath = "/home/localhost/public_html/new/gallery"; // Path to where images should be uploaded to on the server.
$urltoimages = " // Web address to where the images are accessible from.
$maxsize = "500000"; // Example - 20000 is the same as 20kb
// CONFIG END
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
echo "<input type='file' name='file'><br>";
echo "<input name='img_name' type='text' id='img_name' value='title your image'><br>";
echo "<input name='orientation' type='radio' value='ls'>Horizontal<br>";
echo "<input name='orientation' type='radio' value='pt'>Vertical<br>";
echo "<input type='submit' name='Submit' value='Go'>\n";
}
if ($mode == "upload") {
$file = $_FILES['file']['name'];
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "PNG";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big - please reduce file size and try again.";
}
else {
$path = "$serverpath/$file";
$path2 = "$urltoimages/$file";
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists - please rename the file and reupload.";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
// Insert database
require "header.php";
db_connect();
$form_name = urldecode($_POST['img_name']);
$form_orientation = urldecode($_POST['orientation']);
$form_img_location = urldecode($path2);
$sql="INSERT INTO gallery (name, orientation, img_location)
VALUES ('$form_name', '$form_orientation','$form_img_location')";
$result = mysql_query($sql)
or die ('I cannot query database: ' . mysql_error());
// end database code
echo "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
echo "<p><A href='$urltoimages/$file' target='_blank'><strong>$urltoimages/$file</strong></a></p>";
echo "<p><img src='$urltoimages/$file' border='0'>";
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded because it is not a recognised image file. Please try again.</p>"; }
}
}
?>
id
name
img_location
thumb_location
orientation
I know how to send those to such places, but i really dont get how to work with files really. I want to resize any file down to <250kb and also make a thumb of the image. How would i do that? right now, if the file is over 500KB i just reject it, but i am sure i could manipulate it down to 250k or atleast change the dimensions and Qual. any ideas? Someone please help me, i am puting this database together for my fiance's parents and am not charging them, but i want them to be able to interact with it via HTML, because they are not very tech savvy.
//HERE IS MY CODE
<?
// CONFIG
$serverpath = "/home/localhost/public_html/new/gallery"; // Path to where images should be uploaded to on the server.
$urltoimages = " // Web address to where the images are accessible from.
$maxsize = "500000"; // Example - 20000 is the same as 20kb
// CONFIG END
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
echo "<input type='file' name='file'><br>";
echo "<input name='img_name' type='text' id='img_name' value='title your image'><br>";
echo "<input name='orientation' type='radio' value='ls'>Horizontal<br>";
echo "<input name='orientation' type='radio' value='pt'>Vertical<br>";
echo "<input type='submit' name='Submit' value='Go'>\n";
}
if ($mode == "upload") {
$file = $_FILES['file']['name'];
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "PNG";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big - please reduce file size and try again.";
}
else {
$path = "$serverpath/$file";
$path2 = "$urltoimages/$file";
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists - please rename the file and reupload.";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
// Insert database
require "header.php";
db_connect();
$form_name = urldecode($_POST['img_name']);
$form_orientation = urldecode($_POST['orientation']);
$form_img_location = urldecode($path2);
$sql="INSERT INTO gallery (name, orientation, img_location)
VALUES ('$form_name', '$form_orientation','$form_img_location')";
$result = mysql_query($sql)
or die ('I cannot query database: ' . mysql_error());
// end database code
echo "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
echo "<p><A href='$urltoimages/$file' target='_blank'><strong>$urltoimages/$file</strong></a></p>";
echo "<p><img src='$urltoimages/$file' border='0'>";
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded because it is not a recognised image file. Please try again.</p>"; }
}
}
?>