<script> function submitFun(){ //逻辑判断 return true; //允许表单提交 //逻辑判断 return false;//不允许表单提交 } </script> <form onsubmit="reture submitFun();"> //注意此处不能写成 onsubmit="submitFun();"否则将表单总是提交 </form>
作者: leokim
图片ajax上传
用的是CI框架
后端代码:
<?php class Upload extends MY_Controller { function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); } function index() { $data = array(); $data['upload_url'] = site_url('upload/ajax_upload'); $this->load->view('upload', $data); } function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '1024'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); if (!$this->upload->do_upload('AidImg')) { echo("<script>parent.callback('" . $this->upload->display_errors() . "',false)</script>"); exit; } else { $data = array('upload_data' => $this->upload->data()); $img_path = base_url() . 'uploads/'; echo "<script>parent.callback('" . $data['upload_data']['file_name'] . "',true,'" . $img_path . "')</script>"; exit; } } } ?>
前端代码:
<html> <head> <title>Upload Form</title> <script type="text/javascript" src="<?php echo base_url() ?>access/js/jquery-1.8.0.min.js"></script> </head> <body> <form id="formImg" action="do_upload" method="post" target="hidden_frame" enctype="multipart/form-data"> <div> <input type="hidden" name="sh_id" id="sh_id" value="{$id}"> <!--这里的{$id}大家可以随便填1个进去--> <input id="AidImg" type="file" name="AidImg" onchange="uploadImg()"/> <div style="display:none;" id="imgError">图片不可为空</div> <iframe style="display:none" name='hidden_frame' id="hidden_frame"></iframe> <div><img id="p_img" src="" width="80" height="80"/> </div> <span class="help_inline">尺寸:80*80</span> </div> </form> </body> </html> <script> function uploadImg() { var names = $("#AidImg").val().split("."); if (names[1] != "gif" && names[1] != "GIF" && names[1] != "jpg" && names[1] != "JPG" && names[1] != "png" && names[1] != "PNG") { $("#imgError").html("<span>" + "图片必须为gif,jpg,png格式" + "</span>"); $("#formImg .help-inline").hide(); $("#imgError").show(); return; } $("#formImg").submit(); $("#imgError").show(); $("#imgError").html("图片上传中ing"); } function callback(message, success, path) { if (success == false) { $("#imgError").html("<span>" + message + "</span>"); $("#imgError").show(); } else { $("#imgError").hide(); $(".fromtrs").show(); $("#formImg .help-inline").hide(); var paths = path; $("#p_img").attr("src", path + message); $("#p_img").attr("imgname", message); //这里由于数据库里只存入图片名称加后缀名,故和路径拆开了 } } </script>
Using Form-based File Upload in Snoopy
Snoopy is capable of handling form-based file uploads according to RFC's 1867
and 2388. This note describes how to use Snoopy in a number of different file
upload scenarios. Snoopy will handle multiple file upload fields per request
and multiple files per field. Snoopy can also suggest a different filename in
the upload request from the "real" local filename. Snoopy can also put
Content-type into the file upload request on a per file basis.
EXAMPLE 1: SIMPLE FILE UPLOAD
In this example there is a single field with a single file to be uploaded and
nothing fancy. Note that it is necessary to call the set_submit_multipart()
function for the file upload to work. The filename suggested to the server
will be "myfile.txt" since the path will be removed.
include "Snoopy.class.inc";
$snoopy = new Snoopy;
$upload_url = "http://www.somedomain/upload.cgi";
$upload_vars = array();
$upload_files["FIELD1"] = "/home/me/myfile.txt";
$snoopy->set_submit_multipart();
if($snoopy->submit($upload_url, $upload_vars, $upload_files))
echo "<PRE>".$snoopy->results."</PRE>\n";
else
echo "error with file upload: ".$snoopy->error."\n";
EXAMPLE 2: MULTIPLE FILES IN A SINGLE FIELD
Snoopy will support sending multiple files in response to a single form field.
This example works when sending multiple files to an Apache/PHP server. Other
servers may not support this in quite the same way.
include "Snoopy.class.inc";
$snoopy = new Snoopy;
$upload_url = "http://www.somedomain/upload.php";
$upload_vars = array();
$upload_files["FIELD1[]"] = array("/home/me/myfile1.txt", "/home/me/myfile2.txt");
$snoopy->set_submit_multipart();
if($snoopy->submit($upload_url, $upload_vars, $upload_files))
echo "<PRE>".$snoopy->results."</PRE>\n";
else
echo "error with file upload: ".$snoopy->error."\n";
EXAMPLE 3: SPECIFYING FILENAMES and CONTENT TYPES
Some hosts are fussy about the filename that is passed to them by the file
upload request. We can overcome this by getting Snoopy to suggest a different
filename in the request than the "real" local filename. We can also get
Snoopy to specify an optional content type for each file. This is achieved by
having each file entry be an array of parameters instead of a simple filename.
include "Snoopy.class.inc";
$snoopy = new Snoopy;
$upload_url = "http://www.somedomain/upload.cgi";
$upload_vars = array();
$upload_files["FIELD1[]"] = array(
array("name" => "/home/me/myfile1.txt",
"remotename" => "C:\UPLOAD.TXT",
"type" => "text/plain"),
array("name" => "/home/me/myfile2.tiff",
"remotename" => "C:\UPLOAD.TIF",
"type" => "image/tiff")
);
$snoopy->set_submit_multipart();
if($snoopy->submit($upload_url, $upload_vars, $upload_files))
echo "<PRE>".$snoopy->results."</PRE>\n";
else
echo "error with file upload: ".$snoopy->error."\n";
js 获取月份最后一天
var myDate = new Date(); var year = myDate.getFullYear(); var month = myDate.getMonth()+7; var day = new Date(year,month,0); var lastdate = year + '-' + month + '-' + day.getDate();
PHP – 在类中使用array_filter时回调函数的问题
在类内使用应该以数组形式传入this
private function getMutualFromSina ($focusList) { return array_filter($focusList, array($this,"filterSinaList")); } private function filterSinaList ($value) { return in_array($value, $this->fansList); }
live防止触发多次
在live之前给选择器加上die() 结束该选择器之前绑定的所有事件
ci判断update是否执行成功
$this->db->affected_rows();
mysql 最大值最小值
select max(字段名) from tableName limit 0,1 最大
select min(字段名) from tableName limit 0,1 最小
select * from tableName order by 字段名 DESC limit 0,1 最大
select * from tableName order by 字段名 ASC limit 0,1 最小
JP retuen 涉及到的表
JP retuen 设计到的表
select group_concat(voucher_id) from voucher where prefix='JP50' AND voucher_no BETWEEN 2146 AND 2160 select * from voucher_action where voucher_id in(16146,16147,16148,16149,16150,16151,16152,16153,16154,16155,16156,16157,16158,16159,16160) and action_id = 30 select * from voucher_campaign_issue where voucher_id in(16146,16147,16148,16149,16150,16151,16152,16153,16154,16155,16156,16157,16158,16159,16160) select * from voucher_request_approve where request_id = 23070 select * from voucher_batch where batch_id = 46366 select * from voucher_batch_no_section where batch_id = 46366 UPDATE voucher SET type_id =0,status_id=1,stock_id=35, expiry_date=NULL WHERE voucher_id IN (16146,16147,16148,16149,16150,16151,16152,16153,16154,16155,16156,16157,16158,16159,16160,16161,16162,16163,16164,16165,16166,16167)DELETE FROM voucher_actionWHERE voucher_id IN (16146,16147,16148,16149,16150,16151,16152,16153,16154,16155,16156,16157,16158,16159,16160,16161,16162,16163,16164,16165,16166,16167) AND action_id = 30DELETE FROM voucher_campaign_issueWHERE voucher_id IN (16146,16147,16148,16149,16150,16151,16152,16153,16154,16155,16156,16157,16158,16159,16160,16161,16162,16163,16164,16165,16166,16167)DELETE FROM voucher_request_approveWHERE request_id = 23070
Centos svn搭建
你看到的这个文章来自于http://www.cnblogs.com/ayanmw
基本的安装包有: subversion httpd/ svn的httpd的mod_dav_svn mod_authz_svn 两个模块.(yum install mod_dav_svn subversion httpd )
svn的服务形式应该是有两种: 1 通过svnserve建立的 通过svn://ip:port 端口默认是3690,这种形式; 2 通过apache httpd或者其他的web服务器的扩展模块,进行svn管理
对于svnserve,通过svnserve var/www/svn 这种形式建立 daemon的后台进程,但是结束要 kill `pgrep svnserve` 这种形式 来kill掉,不知道有没有直接的比如 stop的方式.
通过http服务器来管理svn也很不错,可以很方便的浏览.其配置过程如下(首先几个软件都安装,这就不用说了.):
1.在 /etc/httpd/module下面 有两个 mod 关于 svn的.
2.在/etc/httpd/config.d/下有一个subversion.conf(没有就建立一个),其内容是:
LoadModule dav_module modules/mod_dav.so LoadModule dav_svn_module modules/mod_dav_svn.so <Location /svn> DAV svn SVNPath /var/www/svn/ AuthType Basic AuthName "Subversion repos" AuthUserFile /var/www/svn/repos1/conf/passwd Require valid-user </Location> # To create a new repository "http://localhost/repos/stuff" using # this configuration, run as root: # # # cd /var/www/svn # # svnadmin create stuff # # chown -R apache.apache stuff # # chcon -R -t httpd_sys_content_t stuff #<Location /repos> # DAV svn # SVNParentPath /var/www/svn # # # Limit write permission to list of valid users. # <LimitExcept GET PROPFIND OPTIONS REPORT> # # Require SSL connection for password protection. # # SSLRequireSSL # # AuthType Basic # AuthName "Authorization Realm" # AuthUserFile /path/to/passwdfile # Require valid-user # </LimitExcept> #</Location>
其中/var/www/svn是准备放仓库的目录,这个目录可以放置多个代码仓库,AuthUserFile就是用户和密码的文件,也可以移动到其他地方单独管理.
/var/www/svn 下面可以通过 svnadmin createa /var/www/svn/repos1 来建立一个空的仓库.还可以建立多个仓库;这个目录貌似最好 给apche用户所有权限:chown -R apache.apache /var/www/svn ;在repos1/conf目录下可以进行一些账号密码 配置,就不多说了.建立的其他仓库 可以拷贝这些conf文件
其中AuthUserFile 是如何制作的呢?
其中ar/www/svn是准备放仓库的目录,这个目录可以放置多个代码仓库,AuthUserFile就是用户和密码的文件,也可以移动到其他地方单独管理.
ar/www/svn 下面可以通过 svnadmin createa ar/www/svn/repos1 来建立一个空的仓库.还可以建立多个仓库;这个目录貌似最好 给apche用户所有权限:chown -R apache.apache ar/www/svn ;在repos1/conf目录下可以进行一些账号密码 配置,就不多说了.建立的其他仓库 可以拷贝这些conf文件
其中AuthUserFile 是如何制作的呢?
下面就是一个示例,创建两个用户 a b,密码 aaa,bbb,再删除。查看密码文件内容:
[root@src-server websvn]# htpasswd accesspwd a htpasswd: cannot modify file accesspwd; use '-c' to create it [root@src-server websvn]# htpasswd -c accesspwd a New password: Re-type new password: Adding password for user a [root@src-server websvn]# ll accesspwd -rw-r--r-- 1 root root 16 Jun 23 02:03 accesspwd [root@src-server websvn]# htpasswd accesspwd b New password: Re-type new password: Adding password for user b [root@src-server websvn]# cat accesspwd a:wpEqdKjINQsvM b:JEpHUbhZZP3fc [root@src-server websvn]# htpasswd -D accesspwd b Deleting password for user b [root@src-server websvn]# cat accesspwd a:wpEqdKjINQsvM [root@src-server websvn]#
3. sudo service httpd restart 重启httpd apache 服务. 貌似很简单呢..回来再整理下svn的命令 补充.
然后通过 http://IP/svn/repos1可以访问这个仓库,可以建立多个仓库同时访问.不过直接访问 IP/svn 无法列出仓库的列表,apache显示 "forbidden \n You don't have permission to access /svn on this server"
对于一些svn的web管理程序也有,比如ViewVC 还有一些其他的管理svn的web程序,最好可以在web端创建仓库、权限管理就好了。目前寻找这样的svn web管理程序中。
CentOS 安装websvn直接yum即可,不需要配置mysql,只需要php的支持即可。
查看websvn的包文件
下面就是vim /etc/websvn/config.php,其实这个文件就是/usr/websvn/include/config.php,只是做了一个链接到etc目录,这种方法对于这种需要配置的web程序来说,还真是方便。
[root@src-server ~]# ll /etc/websvn/config.php -rw-r--r-- 1 root root 21210 Jun 24 18:48 /etc/websvn/config.php [root@src-server ~]# ll /usr/share/websvn/include/config.php lrwxrwxrwx 1 root root 33 Jun 23 01:01 /usr/share/websvn/include/config.php -> ../../../../etc/websvn/config.php [root@src-server ~]#
这里需要修改的配置选项有:
$config->parentPath('/srv/svn/');
$config->useMultiViews();
############ $config->useAuthenticationFile('/srv/svn/passwd');#这里是因为我 不知道如何在websvn上登录我的账号
$config->setBlockRobots();#防止搜索程序收录
$config->expandTabsBy(4);#默认的8 似乎并不适合我的习惯
$config->useEnscript();##语法高亮 建议安装GNU Enscript高亮显示程序包,官方下载:http://www.iki.fi/~mtr/genscript/
# 关于编码 我不知道如何设置,SetInputEncoding 对于我的websvn-2.3.3不起作用,反而websvn出现500错误。
修改/etc/httpd/conf.d/websvn.conf 添加基本权限认证
这里需要修改的配置选项有: $config->parentPath('/srv/svn/'); $config->useMultiViews(); ############ $config->useAuthenticationFile('/srv/svn/passwd');#这里是因为我 不知道如何在websvn上登录我的账号 $config->setBlockRobots();#防止搜索程序收录 $config->expandTabsBy(4);#默认的8 似乎并不适合我的习惯 $config->useEnscript();##语法高亮 建议安装GNU Enscript高亮显示程序包,官方下载:http://www.iki.fi/~mtr/genscript/ # 关于编码 我不知道如何设置,SetInputEncoding 对于我的websvn-2.3.3不起作用,反而websvn出现500错误。 修改/etctpd/conf.d/websvn.conf 添加基本权限认证