导航:首页 > 编程语言 > phpisfile

phpisfile

发布时间:2022-05-20 20:57:53

php+mysql图片的插入、显示操作代码

如果存图片流,数据库会非常庞大,建议还是存路径,图片放到统一的目录下,方便管理
存就是insert 字段用vchar的存相对路径就可以了
读就是查数据库 然后放到数组里 、
显示<img src='读出来的变量'>就可以了

function uploadPhoto ($file) {

$this->result = false;
$this->error = false;
// -- save parameters
$this->_file = $file;
//get path
$this->createUploadDir();
$this->_destination=SystemProperties::$UPLOAD_ROOT_PATH['photo'];
//if (!is_null($allowed)) { $this->_allowed = $allowed; } else { $this->_allowed = array('jpg','jpeg','gif','png'); }

// -- check that FILE array is even set
if (isset($file) && is_array($file) && !$this->upload_error($file['error'])) {

// -- cool, now set some variables
$fileID=$this->_IDGenerator->getNextId('IMAGE');
$fileExt=$this->ext($file['name']);
$fileName =$fileID.'.'.$fileExt;
$this->createFileDir('image',$fileName);
$fileTmp = $file['tmp_name'];
//$fileSize = $file['size'];
//$fileType = $file['type'];
$fileError = $file['error'];

// -- update name
$this->_name = $this->_destination.$fileName;
// -- it's been uploaded with php
if (is_uploaded_file($fileTmp)) {

// -- where to put the file?

$filePath=$this->_fileUtil->getFilePath($fileName);

$output = $this->_destination.$filePath['filePath'];

//resize the img first

$isFileName_f=$this->resizeImage($this->_file,'f',$filePath['noExtFileName'].'_f'.$filePath['ext']);

//or resize the img like this,choosed type in ('a','b','c')

//$isFileName_b=$this->resizeImage($this->_file,'b',$filePath['noExtFileName'].'_b'.$filePath['ext']);

if($isFileName_a==true && $isFileName_b==true && $isFileName_c==true && $isFileName_d==true){

// -- just upload it

if (move_uploaded_file($fileTmp, $output)) {

chmod($output, 0644);

$this->result = basename($this->_name);

return $this->result;

} else {

$this->error("Could not move '$fileName' to '$this->_destination'");

}

}
} else {

$this->error("Possible file upload attack on '$fileName'");
}
} else {
$this->error("Possible file upload attack");
}
}

用php框架的,和纯php写不一样,但是问题不大就是一个思路,没有完全通用的代码,前台加个上传框,做个form传到后台就不用写了吧,传过来的参数$file就是文件,也是个数组用$_FILE[]能看到,首先校验后缀名或者前台js校验,move_uploaded_file这句是最重要的一句,其他都是辅助准备参数而已,意思就是把传上来的东西放到哪去,路径加文件名 $output 这个参数就是你要保存到数据库的值了

② thinkphp 配置路由

对的,写在项目下面的config.php就好了。

③ iis php伪静态怎么设置

thinkphp :把以下代码保存成web.config文件,放到网站根目录内即可。
<?xml version="1.0" encoding="UTF-8"?><configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ThinkPHP_NiPaiYi" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer></configuration>

④ thinkphp iis 如何去掉index.php

[ IIS ]

如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:

RewriteRule(.*)$/index.php?s=$1[I]

在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:

<rewrite>
<rules>
<rulename="OrgPage"stopProcessing="true">
<matchurl="^(.*)$"/>
<conditionslogicalGrouping="MatchAll">
<addinput="{HTTP_HOST}"pattern="^(.*)$"/>
<addinput="{REQUEST_FILENAME}"matchType="IsFile"negate="true"/>
<addinput="{REQUEST_FILENAME}"matchType="IsDirectory"negate="true"/>
</conditions>
<actiontype="Rewrite"url="index.php/{R:1}"/>
</rule>
</rules>
</rewrite>

参考文档:http://www.kancloud.cn/manual/thinkphp/1866

⑤ thinkphp5 怎么把默认的index去掉

1在Apache根目录conf文件夹下的httpd.conf配置文件中加载mod_rewrite.so模块;
#LoadMole rewrite_mole moles/mod_rewrite.so把前面的警号去掉
2
AllowOverride None 将None改为 All
在APACHE里面去配置 (注意其他地方的AllowOverride也统统设置为ALL)
即:AllowOverride none 改 AllowOverride ALL
保存httpd.conf,重启Apache服务器;
3 确保URL_MODEL设置为2,在项目的配置文件里写 'URL_MODEL' => '2',
4
.htaccess文件必须放到跟目录下,在文件里面添加:
<IfMole mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfMole>

⑥ 创建应用目录后入口文件index.php应如何改写

可以通过URL重写隐藏应用的入口文件index.php
[ Apache ]
1. httpd.conf配置文件中加载了mod_rewrite.so模块
2. AllowOverride None 将None改为 All
3. 把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下

<IfMole mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfMole>

[ IIS ]
如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:
RewriteRule (.*)$ /index\.php\?s=$1 [I]
在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:

<rewrite><rules><rule name="OrgPage" stopProcessing="true"><match url="^(.*)$" /><conditions logicalGrouping="MatchAll"><add input="{HTTP_HOST}" pattern="^(.*)$" /><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /></conditions><action type="Rewrite" url="index.php/{R:1}" /></rule></rules></rewrite>

[ Nginx ]
在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:

location / { // …..省略部分代码 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }}

如果你的ThinkPHP安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。

location /youdomain/ { if (!-e $request_filename){ rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last; }}

——转自ThinkPHP3.2.3开发手册

⑦ 请问php5之后可以用纯面向对象来开发吗

面向对象的开发易于开发和维护以及后期迭代
面向过程其实也是可以的

⑧ 请教各位大神,iis环境下配置thinkphp,页面错误

IIS环境
如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:

⑨ 如何用php读取指定文件夹里所有文件并做成链接

<?php

//设定报错等级,如果是开源程序插件不需要设定

error_reporting(E_ERROR|E_PARSE);

//定义欲读取的目录路径,方便演示,本程序读取的是当前文件所在目录

$path='.';

//获取文件列表数组

$files=ReadFolder($path);

//处理文件列表数组

foreach($filesas$value){

//显示文件链接

echo'<ahref="'.$value.'">'.$value.'</a>';

//为方便查看,输出一个<br/>换行符

echo'<br/>';

}

/*定义自定义函数*/

/**

*获取文件列表

*

*@paramstring $dir 欲读取的目录路径

*@paramboolean$mode0:读取全部;1:仅读取文件;2:仅读取目录

*@returnarray

*/

functionReadFolder($dir,$mode=0){

//如果打开目录句柄失败,则输出空数组

if(!$handle=@opendir($dir))returnarray();

//定义文件列表数组

$files=array();

//遍历目录句柄中的条目

while(false!==($file=@readdir($handle))){

//跳过本目录以及上级目录

if('.'===$file||'..'===$file)continue;

//是否仅读取目录

if($mode===2){

if(isDir($dir.'/'.$file))$files[]=$file;

//是否仅读取文件

}elseif($mode===1){

if(isFile($dir.'/'.$file))$files[]=$file;

//读取全部

}else{

$files[]=$file;

}

}

//关闭打开的目录句柄

@closedir($handle);

//输出文件列表数组

return$files;

}

/**

*判断输入是否为目录

*

*@paramstring$dir

*@returnboolean

*/

functionisDir($dir){

return$dir?is_dir($dir):false;

}

/**

*判断输入是否为文件

*

*@paramstring$file

*@returnboolean

*/

functionisFile($file){

return$file?is_file($file):false;

}

?>

⑩ thinkphp框架开发后台文件管理功能求救

在控制器中 import("ORG.Io.Dir");构建完路径后, $dir = new Dir($path);
$list = $dir->_values;在模板用volist 进行循环输出数组不成功,进行mp($list)为NULL值, 更换为$list = $dir->getIterator();后也不成功,但是进行mp的时候数组数据已经建立,问下这样的数组如何在模板循环输出?? mp数据为以下代码:
object(ArrayObject)#4 (1) { ["storage":"ArrayObject":private] => array(29) { [0] => array(18) { ["filename"] => string(3) "bbb" ["pathname"] => string(15) "F:\wamp\www\bbb" ["owner"] => int(0) ["perms"] => int(16895) ["inode"] => int(0) ["group"] => int(0) ["path"] => string(11) "F:/wamp/www" ["atime"] => int(1313063512) ["ctime"] => int(1312255725) ["size"] => int(0) ["type"] => string(3) "dir" ["ext"] => string(0) "" ["mtime"] => int(1313063512) ["isDir"] => bool(true) ["isFile"] => bool(false) ["isLink"] => bool(false) ["isReadable"] => bool(true) ["isWritable"] => bool(true) } [1] => array(18) { ["filename"] => string(8) "�1�7�1�7�0�5�0�0�1�7�1�7" ["pathname"] => string(20) "F:\wamp\www\�1�7�1�7�0�5�0�0�1�7�1�7" ["owner"] => int(0) ["perms"] => int(16895) ["inode"] => int(0) ["group"] => int(0) ["path"] => string(11) "F:/wamp/www"

阅读全文

与phpisfile相关的资料

热点内容
二次元表格编程 浏览:20
plc编程器保停 浏览:963
如何降低服务器的内存占用率 浏览:868
阿里云服务器是个什么意思 浏览:817
国内最好的数控编程培训学校 浏览:13
222乘104列是算法 浏览:159
程序员沟通正确姿势 浏览:969
魔玩app怎么视频推广 浏览:960
程序员抽奖送礼 浏览:458
北京java程序员薪资 浏览:658
如何创建网络平台或者app 浏览:355
python随机数生成控制概率 浏览:236
压缩机并联运行 浏览:899
两位单片机 浏览:63
四川音乐类投档线的算法 浏览:650
建行app如何改转账卡 浏览:26
android开发升级 浏览:299
要火社区app进不去怎么办 浏览:826
安卓手机上的自定义功能怎么用 浏览:230
方舟服务器怎么购买进去资格 浏览:44