How to restrict the size of image thats to be uploaded .
I am creating a small social network and have space constraints .
So , i dont want to restrict the image size to be confined to certain limit.

Sorry do you want to restrict or resize the image?

If you are trying to create a social networking application you will need either a Java or Flash application to handle the file upload process as PHP is very lacking in this aspect.

Reasons being is that PHP can only handle the file once it has been uploaded to the server. So if the size limit is 1mb and the user tries to upload a 1gb file they will have to wait and upload there file before PHP tells the user that the file is too large.

Hi,
you can check the size and type of the image and restrict the user to upload the
smaller images to u r site.
here is the coding:

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
echo "Upload the file";
}
else
{
echo "Image size is too high";
}

Well Froger , you got a point. In that case will javascript help me or ne other idea which will help me doing that.......

JavaScript & AJAX are useless. The only decent methods are Java (not JavaScript) or Flash. This way you can let the user know that the image is either the wrong format or of a large size etc. BEFORE the user uploads it.

Check out Plupload. It is a very interesting offering that allows you to configure a file uploader using a variety of different runtimes.
Flash, Gears, Silverlight, HTML5, HTML4, etc.

http://www.plupload.com/index.php

hi
you have use the filesize() function to get the image size in bytes

then you have to use if condition to upload the file

if(filesize('noname.gif')<50000) {
// upload the image
}
else{
// decline the image
}

got it

enjoy.....:)

@karuppasamy
Froger already explained why that solution is not a viable solution.

Sorry do you want to restrict or resize the image?

If you are trying to create a social networking application you will need either a Java or Flash application to handle the file upload process as PHP is very lacking in this aspect.

Reasons being is that PHP can only handle the file once it has been uploaded to the server. So if the size limit is 1mb and the user tries to upload a 1gb file they will have to wait and upload there file before PHP tells the user that the file is too large.

so you can use flash is the best solution

Not to contradict but Java is most likely the best in both functionality and usability.

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.