This messages popup on my website. I know its php 4 code but can someone help me to recode this piece to php 5 code .
Deprecated: Function ereg_replace() is deprecated in /public/sites/www.teamcheck.nl/include/functions.php on line 2474
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access images/1_euro11348215148.jpg in /public/sites/www.teamcheck.nl/include/functions.php on line 2483
Warning: getimagesize() [function.getimagesize]: Unable to access images/1_euro11348215148.jpg in /public/sites/www.teamcheck.nl/include/functions.php on line 2515
Warning: getimagesize(images/1_euro11348215148.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /public/sites/www.teamcheck.nl/include/functions.php on line 2515
[php]
$name = ereg_replace("[ '"]+", “_”, $name); // strip quotes, spaces
$new_name = $name.time().".".$ext;
$uploadfile = $uploaddir . $new_name; //$uploaddir . $file_name;
$thumbfile = $thumbdir . $new_name;
// echo “temp Image is:”.$_FILES[$field_id][‘tmp_name’]." upload file:".$uploadfile;
if (move_uploaded_file($_FILES[$field_id]['tmp_name'], $uploadfile)) {
//echo "File is valid, and was successfully uploaded. ($uploadfile)\n";
} else {
switch ($_FILES[$field_id]["error"]) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_INI_SIZE:
print("The uploaded file exceeds the upload_max_filesize directive (".ini_get("upload_max_filesize").") in php.ini.");
break;
case UPLOAD_ERR_FORM_SIZE:
print("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.");
break;
case UPLOAD_ERR_PARTIAL:
print("The uploaded file was only partially uploaded.");
break;
case UPLOAD_ERR_NO_FILE:
print("No file was uploaded.");
break;
case UPLOAD_ERR_NO_TMP_DIR:
print("Missing a temporary folder.");
break;
case UPLOAD_ERR_CANT_WRITE:
print("Failed to write file to disk");
break;
default:
print("Unknown File Error");
}
//echo "Possible file upload attack ($uploadfile)! $field_id<br>\n";
//echo $_FILES[$field_id]['tmp_name']."<br>";
}
$current_size = getimagesize($uploadfile);
$width_orig = $current_size[0];
$height_orig = $current_size[1];
if ($width_orig > $max_width) {
//echo "resizing file...<br>";
// The file
$filename = $uploadfile;
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
//header('Content-type: image/jpeg');
// Get new dimensions
//list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
//echo "type is:".$_FILES[$field_id]['type']."<br>";
//echo "orig file is:".$filename."<br>";
//echo "dest file is:".$thumbfile."<br>";
switch ($_FILES[$field_id]['type']) {
case "image/gif":
touch ($filename);
$uploaded_img = imagecreatefromgif($filename);
imagecopyresampled($image_p, $uploaded_img, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
unlink ($filename); // delete original file
// Output
imagejpeg($image_p, $thumbfile, 100);
break;
case "image/jpg":
case "image/jpeg":
case "image/pjpeg":
touch ($filename);
$uploaded_img = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $uploaded_img, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
unlink ($filename); // delete original file
// Output
imagejpeg($image_p, $thumbfile, 100);
break;
case "image/png":
case "image/x-png":
touch ($filename);
$uploaded_img = imagecreatefrompng($filename);
imagecopyresampled($image_p, $uploaded_img, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
unlink ($filename); // delete original file
// Output
imagejpeg($image_p, $thumbfile, 100);
break;
default:
break;
}
imagedestroy ($uploaded_img);
imagedestroy ($image_p);
} else {
//echo ‘No need to resize.
’;
}
//@unlink($uploadfile); // delete the original file.
return $new_name;
}
###########################################################
function deleteImage($table_name, $object_name, $object_id, $field_id) {
$sql = “SELECT $field_id
FROM $table_name
WHERE $object_name
=’$object_id’”;
$result = mysql_query($sql) or die (mysql_error().$sql);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
if ($row[$field_id] != ‘’) {
// delete the original
@unlink (UPLOAD_PATH.“images/”.$row[$field_id]);
// delete the thumb
//@unlink (IMG_PATH.“thumbs/”.$row[$field_id]);
//echo “
unlnkthis[”.IMG_PATH.“thumbs/$new_name]
”;
}
// yeo su 019 760 0030
}
##########################################################
function saveFile($field_id) {
$uploaddir = UPLOAD_PATH.'docs/';
$ext = substr(strrchr($_FILES[$field_id]['name'], "."), 1);
$name = reverse_strrchr($_FILES[$field_id]['name'], ".");
$name = substr($name, 0, -1);
if ($_SESSION['MDS_ID'] != '') {
$name = $_SESSION['MDS_ID']."_".$name;
}
// echo “NAMEis:[$name]”;
// $name = preg_replace("[ '"]+", “_”, $name); // strip quotes, spaces
$new_name = $name.time().".".$ext;
$uploadfile = $uploaddir . $new_name; //$uploaddir . $file_name;
//echo "te,p Image is:".$_FILES[$field_id]['tmp_name']." upload file:".$uploadfile;
if (move_uploaded_file($_FILES[$field_id]['tmp_name'], $uploadfile)) {
//echo "File is valid, and was successfully uploaded.\n";
} else {
//echo "Possible file upload attack ($uploadfile)!\n";
}
return $new_name;
}
[/php]