![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
[php]
<?
if (phpversion() > "4.0.6") {
echo "PHP ver > 4.0.6
";
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",300000);
define("DESTINATION_FOLDER", "./pic");
$_accepted_extensions_ = "jpg,gif";
if(strlen($_accepted_extensions_) > 0){//strlen取得字串长度
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);//explode --- 切开字串
} else {
$_accepted_extensions_ = array();
}
@$_file_ = $HTTP_POST_FILES['file'];
if(is_uploaded_file($_file_['tmp_name']) && $HTTP_POST_FILES['file']['error'] == 0){
$errStr = "";
$_name_ = $_file_['name'];
$_type_ = $_file_['type'];
$_tmp_name_ = $_file_['tmp_name'];
$_size_ = $_file_['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = "File troppo pesante";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ext_[count($_ext_)-1]);//strtolower --- 将字串转成小写,count --- 计算变数中元素的数目
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = "Estensione non valida";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){//is_dir --- 辨别档案名称是否是个目录
$errStr = "Cartella di destinazione non valida";
}
if(empty($errStr)){//empty --- 测定变数是否设定
if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
echo "ok";
// header("Location: " . no_error);
} else {
echo "error-1";
// header("Location: " . yes_error);
}
} else {
echo "error-2";
// header("Location: " . yes_error);
}
}
?>
<?
$dbname = "pro";
$link = mysql_connect("localhost", "pro_f", "123456")
or die("Can't Connect MySQL!
");
mysql_select_db($dbname);
{
$sql = "INSERT INTO productdata (productpic)VALUES('$productpic')";
if ( !$result = mysql_query($sql) ) {
// 删除档案
unlink($file_path."/".$d_file);
exit();
}
}
?>

