For a new little project of mine I want to be able to store certain things. Text and an image.
Storing the data is simple enough but what I want to do with the images is run a check to see that they are;
1. A certain dimension (150px X 150px)
2. A certain file type (gif)
3. Under a certain size (50kb maybe)
If all of these conform then I want the image name to be stored in the database and places in a folder designated especially for the images.
Say, just for example the fields would be;
Name (text)
Age (integer)
Location (text)
Image (location to the file images/filename1.gif)
I've tried looking at a script I found but don't fully understand it, I was wondering if someone could help me a little on this one
CODE
Send this file: <input name="userfile" type="file" />
CODE
$mime_type = array(1=>"image/jpeg", 2=>"image/gif", 3=>"image/jpg", 4=>"image/pjpeg");
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
// you can change this if you move the uploaded file from the tmp folder.
$uploaddir = '/the/directory/here/uploads/'; // change this
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
if(array_search($_FILES['userfile']['type'],$mime_type)){
if ($_FILES['userfile']['size'] > 100000) {
echo 'file size too large';
exit;
}
if (!copy($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
exit;
}
$new_mimetype = $_FILES['userfile']['type'];
} else {
echo "Wrong file type uploaded.";
exit;
}
} else {
echo "No file Uploaded, or file was empty";
exit;
}
Thanks!