note 45448 deleted from function.getimagesize by tomsommer

From: Date: Tue, 07 Sep 2004 21:48:48 +0000
Subject: note 45448 deleted from function.getimagesize by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76173@lists.php.net to get a copy of this message
Note Submitter: ben at mekhaye dot net ---- I had some trouble getting getimagesize() to work. I kept getting the error message: Warning: getimagesize(filenamehere): failed to open stream: No such file or directory I realized that this page (that is, php.net's getimagesize() page) is not very specific as to what, exactly, the "string filename" that must be passed to getimagesize() <i>is</i>. I had the following code, handling the uploaded file upon submit: global $userfile; // get rid of magic quotes and slashes and all that $userfile = stripslashes($userfile); if (is_uploaded_file($userfile)) { $name = $_FILES['userfile']['name']; $mime = $_FILES['userfile']['type']; $size = $_FILES['userfile']['size']; $tmp_name = $_FILES['userfile']['tmp_name']; // Open the uploaded file $file = fopen($userfile, "r"); // Read in the uploaded file $fileContents = fread($file, filesize($userfile)); // HERE'S THE IMPORTANT PART: // is the file an image? if ($image_info = getimagesize($file)) { $width = $image_info[0]; $height = $image_info[1]; } This produced the afforementioned error: Warning: getimagesize: failed to open stream: No such file or directory So I tried passing different things to getimagesize: $file, $userfile, stripslashes($userfile), $name (set to $_FILES['userfile']['name'] ), $tmp_name (set to $_FILES['userfile']['tmp_name'] ). $tmp_name (set to $_FILES['userfile']['tmp_name'] ) worked like a charm; none of the others worked. It wasn't obvious to me that $_FILES['userfile']['tmp_name'] was what I'd need to pass to getimagesize().

« previous php.notes (#76173) next »