Change php settings

Status
Not open for further replies.

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
Sorry if this isn't the right place to post..

I am trying to change my php settings as I believe the max_file upload is set too high and is not limiting user uploads as I have specified in my php script. However I only know how to view the settings not change them . . anyone know?
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
The max upload can't be set too high. Anything lower should still upload.
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
Yes but I only want users to be able to upload 200kb or so otherwise my server will be too full - the max_upload_size is currently set to 35M. So how can I change it?
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
Just thinking that if the php settings for the max_upload_size are too big this is no reason that my script isn't restricting the upload file size for users. After all I want to upload files that are bigger than I want to allow users to upload so the script is imperative - unfortunately it isn't functioning as it should be and is continuing to upload files of any size. Perhaps you could take a look at it for me and maybe suggest why it isn't working. I would really appreciate that.

PHP:
<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
)
	{
	if ($_FILES["file"]["error"] > 0)
	{
	echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
	}
	else
	{
		if($_FILES["file"]["size"] > 20000){
		echo 'the file is too big';
		}
		else
		{
		echo "Upload: " . $_FILES["file"]["name"] . "<br />";
		echo "Type: " . $_FILES["file"]["type"] . "<br />";
		echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
		echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
		}
			if (file_exists("upload/" . $_FILES["file"]["name"]))
			{
			echo $_FILES["file"]["name"] . " already exists. ";
			}
			else
			{
			move_uploaded_file($_FILES["file"]["tmp_name"],
			"upload/" . $_FILES["file"]["name"]);
			echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
			}
		}
	}
else
{
echo "Invalid file";
}
?>
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Try this.

PHP:
<?php
ini_set('upload_max_filesize', '200K');
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
)
    {
    if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
        if($_FILES["file"]["size"] > 20000){
        echo 'the file is too big';
        }
        else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
        }
            if (file_exists("upload/" . $_FILES["file"]["name"]))
            {
            echo $_FILES["file"]["name"] . " already exists. ";
            }
            else
            {
            move_uploaded_file($_FILES["file"]["tmp_name"],
            "upload/" . $_FILES["file"]["name"]);
            echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
            }
        }
    }
else
{
echo "Invalid file";
}
?>
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
Thanks Christopher . . I used this exact code and it still allowed a file bigger than the permitted limit to be uploaded with the following message:

the file is too bigStored in: upload/file.jpg

So it is displaying the error message but also uploading it . . I am really stuck with this one and have no idea why it won't restrict the file size. Please help!!

I have since realised that the upload_max_filesize hasn't changed (still 35M) so perhaps there is a problem with the first line:

ini_set('upload_max_filesize', '200K');
 
Last edited:
Status
Not open for further replies.
Top