📄 ps_main.inc
字号:
<?php/* * ps_main file * * Copyright (c) Edikon Corporation. All rights reserved. * Distributed under the phpShop Public License (pSPL) Version 1.0. * * $Id: ps_main.inc,v 1.1.1.1 2004/07/27 14:58:34 pablo Exp $ * *//**************************************************************************** name: validate_image** created by: jep** description: Validates an uploaded image. Creates UNIX commands to be used** by the process_images function, which has to be called after** the validation.**** parameters: ** - $d The array containing a the image upload information.** - $d[$field_name] : PHP passes the local temp filename for the image** upload here.** - $d[$field_name . "_name"] : PHP passes the original filename of the** uploaded file here.** - $d[$field_name . "_curr"] : This must be passed by the form that** uploads the images. It must contain** the filename of the current image for** the field_name.**** - $field_name The name of the field in the data base that is used to** store the image filename. This name has to be the one** used in the Upload Form Object so that all image upload** vars can be accessed from the $d array.**** - $table_name The name of the table where the image belongs. This ** variable indicates the subdirectory where the image ** files will be placed. This directory is based on the** vendor_image_path value found on the vendor table in** the database.**** returns:** - If an image upload was not requested for field_name, the function** returns TRUE.**** - If an image upload was requested for field_name:** - TRUE if image was uploaded to the local drive, the file is readable,** the image type is valid, and the destination directory is writeable.** - FALSE otherwise.**** - If an image delete was requested:** - TRUE if the directory is writeable.** - FALSE otherwise.**** - $d["$field_name"] : The filename (without path) to where** the image was saved is returned here.**** - $d["image_commands"] : The commands to be executed by the process_images** function are returned as a string here. The** commands are EVAL commands separated by ";"**** - $d["error"] : Error messages returned here.** ***************************************************************************/ function validate_image(&$d,$field_name,$table_name) { global $ps_vendor_id; require_once("vendor/lib/ps_vendor.inc"); $ps_vendor = new ps_vendor; $temp_file = $d[$field_name]; $orig_file = $d[$field_name . "_name"]; $curr_file = $d[$field_name . "_curr"]; $file_size = $d[$field_name . "_size"]; /* If nothing was entered in the Upload box, there is no image to ** process */ if (!$orig_file) { $d[$field_name] = $curr_file; return true; } /* Generate text to dispaly in error messages */ if (eregi("thumb",$field_name)) { $image_type = "thumbnail image"; } elseif (eregi("full",$field_name)) { $image_type = "full image"; } else { $image_type = ereg_replace("_"," ",$field_name); } /* Generate the path to images */ $path = WEBROOT; if ($d["vendor_image_path"]) { $path .= $d["vendor_image_path"]; } elseif ($ps_vendor_id) { $path .= $ps_vendor->get_field($ps_vendor_id,"vendor_image_path"); } elseif ($d["vendor_id"]) { $path .= $ps_vendor->get_field($d["vendor_id"],"vendor_image_path"); } else { $d["error"] .= "ERROR:process_image: Could not resolve vendor image "; $d["error"] .= "path.<BR>"; return false; } $path .= $table_name . "/"; /* If User types "none" in Image Upload Field */ if ($orig_file == "none") { /* If there is a current image file */ if ($curr_file) { /* Check permissions to delete from $path */ if (!is_writeable($path)) { $d["error"] .= "ERROR: Cannot delete from $image_type directory."; $d["error"] .= "<BR>$path<BR>"; return false; } else { $d["image_commands"] .= "\$ret = unlink(\"$path$curr_file\");"; } } $d[$field_name] = ""; return true; } /* If upload fails */ elseif($orig_file and $temp_file == "none") { $d["error"] .= "ERROR: $image_type upload failed."; return false; } /* Check permissions to read temp file */ if (!is_readable($temp_file)) { $d["error"] .= "ERROR: Cannot read uploaded $image_type temp file.<BR>"; return false; } /* Generate Image Destination File Name */ $to_file = md5(uniqid("PHPShop")); /* Check image file format */ $image_info = getimagesize($temp_file); switch($image_info[2]) { case 1: $to_file .= ".gif"; break; case 2: $to_file .= ".jpg"; break; case 3: $to_file .= ".png"; break; default: $d["error"] .= "ERROR: $image_type file is invalid.<BR>"; return false; } /* ** If it gets to this point then there is an uploaded file in the system ** and it is a valid image file. */ /* Check permissions to write to destination directory */ if (!is_writeable($path)) { $d["error"] .= "ERROR: Cannot write to $image_type destination "; $d["error"] .= "directory.<BR>$path<BR>"; return false; } /* If Updating */ if ($curr_file) { /* Command to remove old image file */ $d["image_commands"] .= "\$ret = unlink(\"$path$curr_file\");"; } /* Command to move uploaded file into destination directory */ $d["image_commands"] .= "\$ret = copy(\"$temp_file\", \"$path$to_file\");"; /* Return new image file name */ $d[$field_name] = $to_file; return true;}/**************************************************************************** name: process_images** created by: jep** description: ** parameters:** returns:***************************************************************************/ function process_images(&$d) { if ($d["image_commands"]) { $commands = explode(";",ereg_replace(";$","",$d["image_commands"])); $d["image_commands"] = ""; $cnt = count($commands); for ($i=0;$i<$cnt;$i++) { eval($commands[$i] . ";"); if ($ret == False) { $d["error"] .= "ERROR: Image Update command failed.<BR>"; $d["error"] .= $commands[$i] . "<BR>"; return false; } } } return true;}/**************************************************************************** name: process_date_time** created by: jep** description: ** parameters:** returns:***************************************************************************/ function process_date_time(&$d,$field,$type="") { $month = $d["$field" . "_month"]; $day = $d["$field" . "_day"]; $year = $d["$field" . "_year"]; $hour = $d["$field" . "_hour"]; $minute = $d["$field" . "_minute"]; $use = $d["$field" . "_use"]; $valid = true; /* If user unchecked "Use date and time" then time = 0 */ if (!$use) { $d[$field] = 0; return true; } if (!checkdate($month,$day,$year)) { $d["error"] .= "ERROR: $type date is invalid."; $valid = false; } if (!$hour and !$minute) { $hour = 0; $minute = 0; } elseif ($hour < 0 or $hour > 23 or $minute < 0 or $minute > 59) { $d["error"] .= "ERROR: $type time is invalid."; $valid = false; } if ($valid) { $d[$field] = mktime($hour,$minute,0,$month,$day,$year); } return $valid; }/**************************************************************************** * function: validate_email * created by: Gregory Day * description: Validates an e-mail address. Only checks that the format * is valid. It does not validate that the address will * work. * parameters: $email: Email address to validate * returns: true: Email address is valid * false: Email address is not valid ****************************************************************************/function validate_email ( $email ) { if(ereg('^[_a-z0-9A-Z+-]+(\.[_a-z0-9A-Z+-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)*$', $email)) { return(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -