I need to know what i would have to do with this code in order to reduce/compress the size of the image being uploaded if a the image being uploaded is over 1mb.
<form enctype="multipart/form-data" action='upcomg.php' method="post" name="changer">
<input name="MAX_FILE_SIZE" value="83886080" type="hidden">
<label>Please choose a file:</label><input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
<?php
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$query = "INSERT INTO ### ";
$query .= "(##) VALUES ('$data')";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?>
First off, I wouldn't be storing raw image data in the DB. Storing it in a regular old static file will be much quicker and also won't break if your DB goes offline.
But with that being said, you could just put something like this in there:
$file = $_FILES['image']['tmp_name'];
if ( $_FILES['image']['size'] > 1024*1024 )
$file = compress($file);
Do you have a method of compression already? If not I can help you with that too, but you might want to take a look at Imagick because it already has built in compression.