View Full Version : issue with getimagesize

11-22-2010, 01:57 PM
I am having issue with my upload image script below namely the getimagesize()

I am getting this error

Warning: getimagesize(party.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\wamp\www\test_001\pic.php on line 18

the image moves and renames but it just doesn't give me the image size warnings as the image is well over the specified size.

Any help would be appreciated

if ((isset($_POST['action'])) && ($_POST['action'] == "Upload Picture")) {

//check to see if the field is empty
if (!isset($_FILES['largelogo'])<1) {
$largeerr = "No file found";
$allowedExtensions = array("jpg","gif","jpeg","JPG","png", "JPEG");

//get attachment name
$filename = basename(stripslashes($_FILES['largelogo']['name']));
//get image size and check

list($width, $height, $type, $attr) = getimagesize($_FILES['largelogo']['name']);

if (($width>120) || ($height>60)) {
$largeerr = "Your image was too large actual dimensions were $width x $height. Maximium allowed dimensions are 120x60";

//generate new name for attachment for local storage
$newname = md5(date("Y-m-d H:i:s").$filename);
//get extension and add it to new file name.
$extension = end(explode(".",$_FILES['largelogo']['name']));
$newname = $newname.".".$extension;
//get file type for mimes store in db
$filetype = $_FILES['largelogo']['type'];
//check file uploaded correctly and we have generated a correct filename
$largeerr = "<p id=\"returnresults\"><font color=\"red\"><strong>The name of the file was not found</strong></font></p>";
//check allowed file type
if(!in_array($extension, $allowedExtensions)) {
$largeerr = "<p id=\"returnresults\"><font color=\"red\"><strong>Invalid File Type. Please upload an allowed file type.</strong></font></p>";
$newfile = "files/img/".$newname;
$result = @move_uploaded_file($_FILES['largelogo']['tmp_name'], $newfile);
$largeerr = "<p id=\"returnresults\"><font color=\"red\"><strong>There was an error moving the uploaded file</strong></font></p>";
} else {
$query="INSERT INTO `tbldocuments` (`DocName`,`FileName`,`Extension`,`FileType`,`AddedBy`,`upload_time`, `usertype`) VALUES ('$filename','$newname','$extension','$filetype',".$userdetails[0].", NOW(), '1')";
mysql_query($query) or die(mysql_error());
$largeerr = "<p id=\"returnresults\"><font color=\"red\"><strong>Your document has been successfully uploaded onto the system.</strong></font></p>";

11-22-2010, 02:03 PM
$_FILES['largelogo']['name'] is going to contain the name of the original file. You need to use $_FILES['largelogo']['tmp_name'] or wait until it's moved. See the manual (http://php.net/features.file-upload.post-method) for more information.

11-22-2010, 02:08 PM
star thank you

11-22-2010, 02:58 PM
It is uploading and does not show the error message now but I can still upload images above the sizes I specified?

Have I missed something?