大家帮忙看看我在本机运行能上传图片,但是为什么我把代码放到服务器就不能上传图片???
本机用的是:PHPnow-1.5.5_1
程序地址:http://baike.cardbaobao.com/
注册---登录---创建词条---插入图片关于php的设置:http://baike.cardbaobao.com/php.php
下面是代码:
function uploadfile($attachment,$target,$maxsize=1024,$is_image=1){
$result=array ('result'=>false,'msg'=>'upload mistake');
if($is_image){
$attach=$attachment;
$filesize=$attach['size']/1024;
if(0==$filesize){
$result['msg'] = '上传错误';
return $result;
}
if(substr($attach['type'],0,6)!='image/'){
$result['msg'] ='格式错误';
return $result;
}
if($filesize>$maxsize){
$result['msg'] ='文件过大';
return $result;
}
}else{
$attach['tmp_name']=$attachment;
}
$filedir=dirname($target);
file::forcemkdir($filedir);
if(@copy($attach['tmp_name'],$target) || @move_uploaded_file($attach['tmp_name'],$target)){
$result['result']=true;
$result['msg'] ='上传成功';
}
if(!$result['result'] && @is_readable($attach['tmp_name'])){
@$fp = fopen($attach['tmp_name'], 'rb');
@flock($fp, 2);
@$attachedfile = fread($fp, $attach['size']);
@fclose($fp);
@$fp = fopen($target, 'wb');
@flock($fp,2);
if(@fwrite($fp, $attachedfile)) {
@unlink($attach['tmp_name']);
$result['result']=true;
$result['msg']= '上传失败';
}
@fclose($fp);
}
return $result;
}
本机用的是:PHPnow-1.5.5_1
程序地址:http://baike.cardbaobao.com/
注册---登录---创建词条---插入图片关于php的设置:http://baike.cardbaobao.com/php.php
下面是代码:
function uploadfile($attachment,$target,$maxsize=1024,$is_image=1){
$result=array ('result'=>false,'msg'=>'upload mistake');
if($is_image){
$attach=$attachment;
$filesize=$attach['size']/1024;
if(0==$filesize){
$result['msg'] = '上传错误';
return $result;
}
if(substr($attach['type'],0,6)!='image/'){
$result['msg'] ='格式错误';
return $result;
}
if($filesize>$maxsize){
$result['msg'] ='文件过大';
return $result;
}
}else{
$attach['tmp_name']=$attachment;
}
$filedir=dirname($target);
file::forcemkdir($filedir);
if(@copy($attach['tmp_name'],$target) || @move_uploaded_file($attach['tmp_name'],$target)){
$result['result']=true;
$result['msg'] ='上传成功';
}
if(!$result['result'] && @is_readable($attach['tmp_name'])){
@$fp = fopen($attach['tmp_name'], 'rb');
@flock($fp, 2);
@$attachedfile = fread($fp, $attach['size']);
@fclose($fp);
@$fp = fopen($target, 'wb');
@flock($fp,2);
if(@fwrite($fp, $attachedfile)) {
@unlink($attach['tmp_name']);
$result['result']=true;
$result['msg']= '上传失败';
}
@fclose($fp);
}
return $result;
}
解决方案 »
- php5.3.3 eval()函数不能用了
- 关于多城市社区的问题
- 求一个算法,得到输入IP在指定的范围内
- PHP的数值操作问题
- cookie怎么会警告的呢
- 新手提问:如何获取内网的ip
- 网站开通,是从网通接的,可有些地方打得开,有些地方打不开,这个怎么办啊?谢谢
- 我用$_FILES上传文件后,根据$_FILES['userfile']['type']来判断文件类型,可是为什么有的jpg或gif文件行,有些就不行,这是为什么?我查
- 各位高手,请问关于PHP中MYSQL3个函数的问题
- 遇到一超难问题,用php怎么获取远程调用者ip,内详,高手进
- mysqldump命令怎么使用啊
- 请教一个REWRITE规则。
http://kaiyuan.hudong.com/down.php
HDWiki4.1(最新版)
function _SERVER($n) { return isset($_SERVER[$n]) ? $_SERVER[$n] : '[undefine]'; }$f_path =_SERVER('DOCUMENT_ROOT');
echo $f_path."---<br>";
$jc_path = file_mode_info($f_path);
/**
* 文件或目录权限检查函数
*
* @access public
* @param string $file_path 文件路径
* @param bool $rename_prv 是否在检查修改权限时检查执行rename()函数的权限
*
* @return int 返回值的取值范围为{0 <= x <= 15},每个值表示的含义可由四位二进制数组合推出。
* 返回值在二进制计数法中,四位由高到低分别代表
* 可执行rename()函数权限、可对文件追加内容权限、可写入文件权限、可读取文件权限。
*/
function file_mode_info($file_path){
$ = 0;
/* 测试文件 */
$test_file = $file_path . '/cf_test.txt';
/* 如果不存在,则不可读、不可写、不可改 */
if (!file_exists($file_path)){
echo $file_path."目录不存在---<br>";
return false;
}
echo $file_path."目录存在---<br>";
/* 如果是目录 */
if (is_dir($file_path)){
/* 检查目录是否可读 */
$dir = @opendir($file_path);
if ($dir === false){
return $; //如果目录打开失败,直接返回目录不可修改、不可写、不可读
echo $file_path."目录,打开失败---<br>";
}
if (@readdir($dir) !== false){
$ ^= 1; //目录可读 001,目录不可读 000
echo $file_path."目录,打开成功---<br>";
}
/* 检查目录是否可写 */
$fp = @fopen($test_file, 'wb');
if ($fp === false){
return $; //如果目录中的文件创建失败,返回不可写。
echo $file_path."目录,文件创建失败------<br>";
}
if (@fwrite($fp, '开始directory access testing.') !== false){
$ ^= 2; //目录可写可读011,目录可写不可读 010
echo $file_path."目录,文件创建成功------<br>";
}
/* 检查目录是否可修改 */
$fp = @fopen($test_file, 'ab+');
if ($fp === false){
return $;
echo $file_path."目录,文件修改失败---------<br>";
}
if (@fwrite($fp, "大家好modify test.结束\r\n") !== false){
$ ^= 4;
echo $file_path."目录,文件修改成功---------<br>";
}
//echo $test_file."文件---------<br>";
$newtest_file = $file_path . '/newcf_test.txt';
//$newt_file = rename($test_file, $newtest_file);
/* 检查目录下是否有执行rename()函数的权限 */
if (@rename($test_file, $newtest_file) !== false){
$ ^= 8;
echo $file_path."rename()函数执行成功---------<br>";
}
}
}?>
我又自己写了一个检查程序,测试本地和服务器,结果是:
本地:
E:/PHPnow-1.5.5_1/htdocs---
E:/PHPnow-1.5.5_1/htdocs目录存在---
E:/PHPnow-1.5.5_1/htdocs目录,打开成功---
E:/PHPnow-1.5.5_1/htdocs目录,文件创建成功------
E:/PHPnow-1.5.5_1/htdocs目录,文件修改成功---------服务器:
D:\web\baike.cardbaobao.com---
D:\web\baike.cardbaobao.com目录不存在---晕死了···怎么会没目录呢???
方法是:
去iis站点属性文件根目录重新设置一下,比方你原来设置的是c:\windows\webroot\hdwiki
现在就设置为c:\windows\webroot
这样就可以了