不带register_globals的图像上传



我使用的图像上传脚本已经停止工作,因为我的主机已经关闭了register_globals。但是,如果没有它,我不知道如何使它工作。如果你能帮助我,我会很高兴。这是代码:

            $uploadedfile = $_FILES['photo']['tmp_name'];
            $src = imagecreatefromjpeg($uploadedfile);
            // get the date from EXIF data 
            $exif = exif_read_data($uploadedfile, 0, true);
            foreach ($exif as $key => $section) {
                foreach ($section as $name => $val) {
                    if ($name == 'DateTimeOriginal') {
                        $the_filename = explode(" ", $val);
                        $the_filenamedate = str_replace(":", "", $the_filename[0]);
                        $the_filenametime = str_replace(":", "", $the_filename[1]);
                        $newfilename = $the_filenamedate."-".$the_filenametime.".jpg";
                        $the_datetime = explode(" ", $val);
                        $the_date = str_replace(":", "-", $the_datetime[0]);
                        $the_time = $the_datetime[1];
                        $datetime = $the_date." ".$the_time;
                        $exif_db = 'y';
                    }
                }
            }
            // use current date and time if no exif data
            if (empty($newfilename)) {
                $newfilename = date("Ymd-His").".jpg";
                $datetime = date("Y-m-d H:i:s");
                $exif_db = 'n';
            }
            // resize if necessary
            list($width,$height) = getimagesize($uploadedfile);
            if ($resize_it == 'y') {
                if ($width > $maxwidth) {
                    $newwidth = $maxwidth;
                    $newheight = ($height/$width)*$newwidth;
                } else {
                    $newwidth = $width;
                    $newheight = ($height/$width)*$newwidth;
                }
            } else {
                $newwidth = $width;
                $newheight = $height;
            }
            $tmp = imagecreatetruecolor($newwidth,$newheight);
            imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
            $filename = $dirpath.$gal_id."/".$newfilename;
            imagejpeg($tmp,$filename,100);
            // create thumbnail
            $uploadedthumb = $_FILES['photo']['tmp_name'];
            $srcthumb = imagecreatefromjpeg($uploadedthumb);
            list($widththumb,$heightthumb) = getimagesize($uploadedthumb);
            if ($widththumb > $heightthumb) {
                $newheightthumb = 100;
                $newwidththumb = ($widththumb/$heightthumb)*$newheightthumb;
            } elseif ($widththumb == $heightthumb) {
                $newheightthumb = 100;
                $newwidththumb = 100;
            } elseif ($widththumb < $heightthumb) {
                $newwidththumb = 100;
                $newheightthumb = ($heightthumb/$widththumb)*$newwidththumb;
            } else {
                $newheightthumb = 100;
                $newwidththumb = ($widththumb/$heightthumb)*$newheightthumb;
            }
            $tmpthumb = imagecreatetruecolor($newwidththumb,$newheightthumb);
            imagecopyresampled($tmpthumb,$srcthumb,0,0,$src_top,$src_left,$newwidththumb,$newheightthumb,$widththumb,$heightthumb);
            $thumbname = $dirpath.$gal_id."/zth_".$newfilename.".jpg";
            imagejpeg($tmpthumb,$thumbname,100);
            // free memory, destroying the source's and the pic's canvas
            imagedestroy($srcthumb);
            imagedestroy($tmpthumb);
            imagedestroy($src);
            imagedestroy($tmp);

提前感谢!

使用$_POST数组读取已发布的表单字段。名为emil的字段的值将在PHP变量$_POST['emil']中,而不是在$emil中。您必须更改读取表单字段的所有实例。

查询字符串中的变量也是如此,查询字符串现在位于$_GET中,cookie位于$_COOKIE中,会话变量位于$_SESSION中。

相关内容

  • 没有找到相关文章

最新更新