up2.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<!--
<form action="get.php" method="post" enctype="multipart/form-data" name="frm" id="frm" onsubmit="return checkInput(this)">
<input type="file" name="fileId0" size=65 /></form> -->
<form action="up.php" method="post" enctype="multipart/form-data">
<input type="file" name='file_img'/>
<input type="submit" name="OK" value="OK" />
</form>
</body>
</html>// -----------------------------------------------
up.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?
include "upfile.php";
/**
* 图片上传方法-来源与PHP100中文网
* $maxsize=500000 = 500k;
* $updir="up/";
* $upfile=$_FILES["file_img"]; public function Get_file_upload($upfile, $maxsize, $updir, $newname = 'date') ;
*/ $maxsize = 500000;
$updir="up/";
$upfile=$_FILES["file_img"]; Get_file_upload($upfile, $maxsize, $updir, $newname) ;
?>
</body>
</html>//// -----------------------------------------------------------------------------------------
upfile.php
<?
/**
* 图片上传方法-来源与PHP100中文网
* $maxsize=500000 = 500k;
* $updir="up/";
* $upfile=$_FILES["file_img"];
*/
public function Get_file_upload($upfile, $maxsize, $updir, $newname = 'date'){ if ($newname == 'date')
$newname = date("Ymdhs"); //使用日期做文件名
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"]; switch ($type) {
case 'image/pjpeg' :
case 'image/jpeg' :
$extend = ".jpg";
break;
case 'image/gif' :
$extend = ".gif";
break;
case 'image/png' :
$extend = ".png";
break;
}
if (empty ($extend)) {
echo '文件类型不正确,只能使用JPG GIF PNG 格式';
}
if ($size > $maxsize) {
$maxpr = $maxsize / 1000;
echo "警告!上传图片大小不能超过";
}
if (move_uploaded_file($tmp_name, $updir . $newname . $extend)) {
return $newname . $extend;
}
}
?>
上传一个图片时提示:Parse error: parse error in D:\php\music\test\upfile.php on line 8也就是这里出错: public function Get_file_upload($upfile, $maxsize, $updir, $newname = 'date'){
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<!--
<form action="get.php" method="post" enctype="multipart/form-data" name="frm" id="frm" onsubmit="return checkInput(this)">
<input type="file" name="fileId0" size=65 /></form> -->
<form action="up.php" method="post" enctype="multipart/form-data">
<input type="file" name='file_img'/>
<input type="submit" name="OK" value="OK" />
</form>
</body>
</html>// -----------------------------------------------
up.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?
include "upfile.php";
/**
* 图片上传方法-来源与PHP100中文网
* $maxsize=500000 = 500k;
* $updir="up/";
* $upfile=$_FILES["file_img"]; public function Get_file_upload($upfile, $maxsize, $updir, $newname = 'date') ;
*/ $maxsize = 500000;
$updir="up/";
$upfile=$_FILES["file_img"]; Get_file_upload($upfile, $maxsize, $updir, $newname) ;
?>
</body>
</html>//// -----------------------------------------------------------------------------------------
upfile.php
<?
/**
* 图片上传方法-来源与PHP100中文网
* $maxsize=500000 = 500k;
* $updir="up/";
* $upfile=$_FILES["file_img"];
*/
public function Get_file_upload($upfile, $maxsize, $updir, $newname = 'date'){ if ($newname == 'date')
$newname = date("Ymdhs"); //使用日期做文件名
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"]; switch ($type) {
case 'image/pjpeg' :
case 'image/jpeg' :
$extend = ".jpg";
break;
case 'image/gif' :
$extend = ".gif";
break;
case 'image/png' :
$extend = ".png";
break;
}
if (empty ($extend)) {
echo '文件类型不正确,只能使用JPG GIF PNG 格式';
}
if ($size > $maxsize) {
$maxpr = $maxsize / 1000;
echo "警告!上传图片大小不能超过";
}
if (move_uploaded_file($tmp_name, $updir . $newname . $extend)) {
return $newname . $extend;
}
}
?>
上传一个图片时提示:Parse error: parse error in D:\php\music\test\upfile.php on line 8也就是这里出错: public function Get_file_upload($upfile, $maxsize, $updir, $newname = 'date'){
这个地方前后用{}括起来看看......
公共函数添加Public修饰就会报错去掉Function 前的 Public就可以了。