I`m uploading images to the database for my website,it works fine))
I want them to be resized to width=160 and height=140.
now i dont know if i should resize them before uploading them to mysql database Or while Displaying them.
Also i dont have Knowledge concerning resize of image.
Please help me in this:
Below is the code i`m using for uploadig images

the max file size is 1052695

if ($_POST['submit']) {

        if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {

          $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
           $query = "INSERT INTO  image SET image='$photo',filetype='$filetype',user='$user',userid='$id' WHERE user='$user'";
		   if ($result) {
            echo "Your files is successfully stored in database"; 
           } else {
           echo"Error detected while trying TO add YOUR photo<br> Try again please";


echo"the file is bigger than the size needed";

do you want the photo to be viewed in original size again?

i have a resizing function. i just need to know if i need to customize it to work with your app.

Resizing images is very server intensive, you wan to do it only once for an image size, and keep that thumbnail saved on the disk. It is better to save the path to the image in mysql but you can also save the binary data. If you need the original image, keep a copy of it on disk also. Usually you have more disk space then you do processing power as there are much fewer image uploads then their are image views.

yes i want the image to viewed in original size again)))so if you KKeith29 you write your function accoding to my code i`ll be glad)))

Member Avatar for Rhyan

First of all, you do not have to store full image in database, but only relative path, or image name. Otherwise you may get your database full of images really quickly, that may result in long delays when opening pages.
Second of all, what digital ehter says is best for those times that you need e.g. a small thumbnail as avatar of a user, to be created. Then you will have both the thumbnail and the original stored as files on the disk, and you have to store relative paths in the DB as well.
If you have a limited disk space on the server, then it will be better for you to have a resizing code that will reduce images for preview purposes only and will save some download time in expense for server processing time.
Once you know your limits, you will have to figure out what code you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.