0

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.

5
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by Froger93
0

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.

0

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";
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

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

0

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.

0

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.....:)

0

@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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.