update_image2.php

$image_info = getimagesize($_FILES["file"]["name"]);
                $image_width = $image_info[0];
                $image_height = $image_info[1];
                print_r("$image_width");

I wonder why $image_width do not have any value?

Recommended Answers

All 6 Replies

this works

list($width, $height) = getimagesize('path to image');
echo "width: " . $width . "<br />";
echo "height: " .  $height;

list($image_width, $image_height) = getimagesize($_FILES["file"]["name"]);

I try this:

 list($width, $height) = getimagesize($newfilename);
                echo "width: " . $width . "<br />";
                echo "height: " . $height;

Result:

testSuccessfully upload pictures
Warning: getimagesize(32191245sociology_big.jpg): failed to open stream: No such file or directory in C:xampphtdocsportaladministrator2adminupdate_image2.php on line 181
width:
height:
Image is too big
1000>650
228>450

No value in width and height.

Your directory doesn't look right to me:
C:xampphtdocsportaladministrator2adminupdate_image2.php

I'd say you're missing some directory separators.Thats why the image can't be found.

if(isset($_POST['ok2'])){

            if (isset($_FILES['file']['name']) && $_FILES['file']['name']!=''){
                $size = getimagesize($_FILES['file']['tmp_name']);
            //echo "<pre>";print_r($size);echo "</pre>";
            $image_width = $size[0];
            $image_height = $size[1];
            //echo "Image width : ".$image_width.'<br>';
            //echo "Image height: ".$image_height;

                }else{
                echo "No files uploaded!";
                }



            //print_r($_POST['location'], 1);
            echo "test";

            if (empty($_GET['image_id']))
                {

                // Picture Upload

                $allowedExts = array("gif", "jpeg", "jpg", "png");
                //$temp = explode(".", $_FILES["file"]["name"]);


                $extension = pathinfo($_FILES["file"]["name"],PATHINFO_EXTENSION);  
                //$extension = end($temp);

                if ((($_FILES["file"]["type"] == "image/gif")
                || ($_FILES["file"]["type"] == "image/jpeg")
                || ($_FILES["file"]["type"] == "image/jpg")
                || ($_FILES["file"]["type"] == "image/pjpeg")
                || ($_FILES["file"]["type"] == "image/x-png")
                || ($_FILES["file"]["type"] == "image/png"))
                && ($_FILES["file"]["size"] < 41943040)  //40MB
                && in_array($extension, $allowedExts)) {

                if ($_FILES["file"]["error"] > 0) {
                echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
                } else {
                echo "Successfully upload pictures";
                //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"]))
                {

                $filename = $_FILES["file"]["name"];
                $i = (rand());
                $ii = (rand());
                $iii = (rand());
                $newfilename = $ii.$iii.$i.$filename;

                //echo $_FILES["file"]["name"] . " new file name is $newfilename. ";
                } else {

                $filename = $_FILES["file"]["name"];
                $i = (rand());
                $newfilename = $i.$filename;

                move_uploaded_file($_FILES["file"]["tmp_name"],
                "images/" . $newfilename);
                //echo "Stored in: " . "upload/" . $newfilename;
                }


                } 

                /*$filename = $_FILES["file"]["name"];
                */
                //$image_info[] = getimagesize($_FILES["file"]["name"]);
                list($width, $height) = getimagesize($newfilename);
                echo "width: " . $width . "<br />";
                echo "height: " . $height;

I wonder why C:xampphtdocsportaladministrator2adminupdate_image2.php there is no "/" there suppose to be "/" in between.

You're still not sending a complete URI to getimagesize(). The file name alone isn't enough. Try:
list($width, $height) = getimagesize('images/' . $newfilename);

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.