为什么要文件名和类名一样php_php文件名和类名相同时include不起作用?
文件名:原来为ValidationCode.php
修改为validate.php后可以正常显示验证码,
浏览器中请求code.php文件中进行显示验证码
width = $width;
$this->height = $height;
$this->num_chars = $num_chars;
}
function showImage(){
$this->createImage();
$this->drawBorder();
$this->drawChars();
$this->outPic();
}
//create canvas
function createImage(){
$this->image = imagecreate($this->width,$this->height);
//$rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));
$back = imagecolorallocate($this->image,0,0,0);
$border = imagecolorallocate($this->image,255,255,255);
imagefill($this->image,0,0,$back);
//imagefilledrectangle($thid->image,self::BORDER,self::BORDER,$this->width-self::BORDER,$this->height-self::BORDER,$border);
//imageline($this->image,1,1,100,100,$rand_color);
//$this->outPic();
}
//draw border
private function drawBorder(){
$outer_bg_color = imagecolorallocate($this->image,0,0,0);
$inner_bg_color = imagecolorallocate($this->image,255,255,255);
imagefill($this->image,0,0,$outer_bg_color);
imagefilledrectangle($this->image,self::BORDER,self::BORDER,$this->width-self::BORDER-1,$this->height-self::BORDER-1,$inner_bg_color);
}
//create char content
function createChar(){
$rand_ascii="";
$rand_type = rand(0,2);
switch($rand_type){
case 0:
$rand_ascii = rand(48,57);
break;
case 1:
$rand_ascii = rand(65,90);
break;
case 2:
$rand_ascii = rand(97,122);
break;
}
$rand_str = sprintf("%c",$rand_ascii);
return $rand_str;
}
//draw char
private function drawChars(){
$x = $this->width/$this->num_chars+1;
$y = $this->height/2;
for($index = 0; $indexnum_chars; $index++){
$rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));
imagechar($this->image,3,$x*$index+2,$y-$y/2,$this->createChar(),$rand_color);
}
}
//out pic
private function outPic(){
header("content-type:image/png");
imagepng($this->image);
}
function __destruct(){
imagedestroy($this->image);
}
}
/*$code = new ValidationCode();
//echo $code->createChar();
$code->showImage();*/
?>
code.php
createChar();
$code->showImage();
?>
这个问题已被关闭,原因:已经自己找到问题原因
回复内容:
文件名:原来为ValidationCode.php
修改为validate.php后可以正常显示验证码,
浏览器中请求code.php文件中进行显示验证码
width = $width;
$this->height = $height;
$this->num_chars = $num_chars;
}
function showImage(){
$this->createImage();
$this->drawBorder();
$this->drawChars();
$this->outPic();
}
//create canvas
function createImage(){
$this->image = imagecreate($this->width,$this->height);
//$rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));
$back = imagecolorallocate($this->image,0,0,0);
$border = imagecolorallocate($this->image,255,255,255);
imagefill($this->image,0,0,$back);
//imagefilledrectangle($thid->image,self::BORDER,self::BORDER,$this->width-self::BORDER,$this->height-self::BORDER,$border);
//imageline($this->image,1,1,100,100,$rand_color);
//$this->outPic();
}
//draw border
private function drawBorder(){
$outer_bg_color = imagecolorallocate($this->image,0,0,0);
$inner_bg_color = imagecolorallocate($this->image,255,255,255);
imagefill($this->image,0,0,$outer_bg_color);
imagefilledrectangle($this->image,self::BORDER,self::BORDER,$this->width-self::BORDER-1,$this->height-self::BORDER-1,$inner_bg_color);
}
//create char content
function createChar(){
$rand_ascii="";
$rand_type = rand(0,2);
switch($rand_type){
case 0:
$rand_ascii = rand(48,57);
break;
case 1:
$rand_ascii = rand(65,90);
break;
case 2:
$rand_ascii = rand(97,122);
break;
}
$rand_str = sprintf("%c",$rand_ascii);
return $rand_str;
}
//draw char
private function drawChars(){
$x = $this->width/$this->num_chars+1;
$y = $this->height/2;
for($index = 0; $indexnum_chars; $index++){
$rand_color = imagecolorallocate($this->image,rand(0,255),rand(0,255),rand(0,255));
imagechar($this->image,3,$x*$index+2,$y-$y/2,$this->createChar(),$rand_color);
}
}
//out pic
private function outPic(){
header("content-type:image/png");
imagepng($this->image);
}
function __destruct(){
imagedestroy($this->image);
}
}
/*$code = new ValidationCode();
//echo $code->createChar();
$code->showImage();*/
?>
code.php
createChar();
$code->showImage();
?>
测试:入口代码
createChar();
$code->showImage();
文件名:
测试结果:
结论:include的时候文件名跟类名没有关系。结果是可以的。我不知道你的为什么不可以。但是我测了是可以的。
真的假的啊!文件名和类名一样引用不起作用,这么神奇!有没有出什么错误提示
相关标签:php
本文原创发布php中文网,转载请注明出处,感谢您的尊重!
为什么要文件名和类名一样php_php文件名和类名相同时include不起作用?相关推荐
- java中文件名和类名之间的关系
在java里,文件名与类名之间的关系,有下面这些约束: Java保存的文件名必须与类名一致 如果文件中只有一个类,文件名必须与类名一致 一个Java文件中只能有一个public类 果文件中不止一个类, ...
- java获取文件名方法,利用Java获取文件名、类名、方法名和行号的方法小结
大家都知道,在C语言中,我们可以通过宏FILE. __LINE__来获取文件名和行号,而在Java语言中,则可以通过StackTraceElement类来获取文件名.类名.方法名.行号,具体代码如下: ...
- java文件中public 类名要和文件名保持一致以及其他细节
1 Java保存的文件名必须与类名一致: 2 如果文件中只有一个类,文件名必须与类名一致: 3 一个Java文件中只能有一个public类:如下面的程序是会在public class This处报错的 ...
- java文件名命名的规则,Java文件名及其他命名规则
http://bbs.csdn.net/topics/70157841 关于JAVA源文件命名的问题 Java文件命名: java程序是由类组成的: java应用程序必须有一个包含main方法的pu ...
- java 文件名加英文字母_Java文件名及其他命名规则
http://bbs.csdn.net/topics/70157841 关于JAVA源文件命名的问题 Java文件命名: java程序是由类组成的: java应用程序必须有一个包含main方法的pu ...
- 怎样更改计算机文件名,电脑如何批量修改文件名|批量修改文件名的几个小方法...
遇到多文件,需要重命名的时候,有些人就头疼了,几百个文件,要是全部都要重命名,要弄到什么时候?虽然说,可以借助第三方的工具,但是有些使用win10的用户觉得麻烦,那还有什么其他方法?这篇文章就是系统吧 ...
- 如何批量修改文件名?批量修改照片文件名和添加前缀
通常我们使用手机或者相机拍摄了一堆照片拷贝到电脑之后,照片的命名通常都是随机混乱的,如果要规范文件命名,你是不是会去一个一个去修改文件名呢?其实完全不需要这么麻烦,今天电脑百事小编就来教大家一个批量快 ...
- matlab怎样改文件名,使用matlab快速修改文件名
使用matlab可以快速修改文件名,例如电影中的文件名有的前缀很长,想删掉,下面的程序比较简单: %修改电影的文件名前缀 %在网上下的电影文件前缀很长,经常需要去掉前准 %下面的程序使用起来比较方便 ...
- 从java代码获取类名_java代码获取当前类类名、方法名
获取类名: 1.在类的实例中可使用this.getClass().getName();但在static method中不能使用该方法: 2.在static method中使用方法:Thread.cur ...
最新文章
- sencha touch 组件选择器getCmp和ComponentQuery.query()的效率解析
- 【Leetcode】79.单词搜索
- Linux查看内存使用情况
- blp模型 上读下写_CreditX在线借贷欺诈检测框架BLP
- tortoise清理本地分支_TortoiseGit操作本地仓库的详细使用方法
- 如何打包和部署air应用程序
- php珠心算源码,深度解析珠心算的“开智”功能
- 二叉树层次遍历python_根据二叉树层序遍历顺序(数组),将其转换为二叉树(Python)...
- 手机号段对应地区编码_什么是编码器?了解两种类型的编码器
- ssh登录工具 putty 和 生成.ppk文件的puttygen工具 如何使用puttygen生成密钥
- 一个屌丝程序猿的人生(二)
- python画椭圆形_Python易学就会(五)turtle绘制椭圆与递归
- 金华万豪、温州万豪、温州乐清万怡、哈尔滨城市中心万枫、九寨英迪格等酒店开业 | 全球旅报...
- 安卓桌面整理app_【小编分享】APP整理大法!跟杂乱无章的手机桌面说拜拜~
- P - Balanced Stone Heaps
- 行内元素和块元素的区别
- 稀疏表示学习笔记--正交阵,协方差
- 农场游戏的开发记录二
- 《小岛经济学》一、前言
- linux挂载opt磁盘,centos挂载硬盘到opt
热门文章
- 设置简体中文_键盘不好用了?看看是不是设置有问题
- 中国象棋将帅问题java_编程之美读书笔记1.2——中国象棋将帅问题
- c++ 多个字符串排序_RPython Data Science系列:数据处理(5)--字符串函数基于R(一)
- 计算机安全的加密技术,计算机安全加密技术研究(4篇)(共14695字).doc
- labview和python混编_将数据从LabView发送到Python并取回
- c++数据结构队列栈尸体_数据结构-栈与队列(二)
- 经济学专业向计算机方向创业,基于市场需求的经济学专业人才培养模式研究
- 计算机网络二级考试类型,二级计算机考试大纲
- c语言字符类型强制换成内码,C语言实现不同汉字系统的内码转换方法
- 嵌入式linux屏幕录制,在MAC系统上进行屏幕录制