I use a image upload script which has stopped working now that my host has turned register_globals off. However, I don't know how do make it work without it. I'd be glad if you could help me out. Here's the code:
$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);
Thanks in advance!
Use the $_POST array to read posted form fields. A field named emil
will have the value in the PHP variable $_POST['emil']
, not in $emil
. You have to change all instances where you read form fields.
The same applies for variables in the querystring, which is now found in $_GET
, cookies in $_COOKIE
and session variables in $_SESSION
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.