用php写 ftp文件上传函数教程
代码如下 | 复制代码 |
<? function phpftp_bottom() { function phpftp_login() { /* This function does not return TRUE/FALSE - it returns the value of function phpftp_connect( $phpftp_user, $phpftp_passwd ) { function phpftp_list( $phpftp_user, $phpftp_passwd, $phpftp_dir ) { function phpftp_cd( $phpftp_user, $phpftp_passwd, $phpftp_dir, $select_directory ) { function phpftp_mkdir( $phpftp_user, $phpftp_passwd, $phpftp_dir, $new_dir ) {
function phpftp_put( $phpftp_user, $phpftp_passwd, $phpftp_dir, $userfile, $userfile_name ) { switch( $function ) { ?> |
在php中创建目录我们会用到mkdir() 函数来创建目录
*/
代码如下 | 复制代码 |
$dir = "abc"; if( mkdir($dir,0777)) { echo '目录'.$dir.'成功创建'; } else { echo '创建目录失败,请检查权限'; } |
/*
代码如下 | 复制代码 |
mkdir函数说明 mkdir(path,mode,recursive,context) path 必需。创建的目录的名称。 mode 必需。默认是 0777。 recursive 必需。设置递归模式。 context 必需。规定文件句柄的环境。 |
mkdir相关实例
http://www.111cn.net/phper/24/mkdir-05.htm
无法创建文件夹原因分析
一、如何不能创建可以设置目录的权限一盘0777就可以,用程序改变目录权限用chmod
二、用ftp
三、用服务器权限就更好办了,
umask是0777的时候,当然是这样,自己手动用chmod改一下不就行了
chmod函数说明
chmod(file,mode)
如:
chmod("/somedir/somefile", 0755);
chmod相关实例
http://www.111cn.net/phper/24/chmod-php.htm
http://www.111cn.net/phper/24/ad7d09f46fce96a82f06fe711adeb47b.htm
最后还是让我找到了解决的方法,就是通过PHP的程序执行函数来实现这个功能,因为现在能解ZIP文件的东西实在是太多啦(你要是不信,可以到有下载软件的地方找找看,保准你不会失望的,我的话不会错呦)。
下面就是该程序的原文件:
#upload.php教程
代码如下 | 复制代码 |
<table border="0" > <form ENCTYPE="multipart/form-data" action="ups教程ave.php" method="post"> <tr> <td>如果是*.ZIP的文件会被自动解压缩 <INPUT NAME="MyFile" TYPE="File" size="50"> </td> </tr> <tr> <td colspan="2" align="center"> <input type="Submit" value=" 上传 " class=iwhite> <input type="reset" value=" 重填 " class=iwhite> </td> </tr> </table> |
</body>
</html>
代码如下 | 复制代码 |
<? //upsave.php //保存上传的文件 $filename="$MyFile_name"; copy($MyFile,"$filename"); unlink($MyFile); //判断是否是ZIP文件 $expand_name=explode(".",$filename); if($expand_name[1] == "zip" or $expand_name[1] == "ZIP") { $str="pkunzip.exe -e $filename "; exec($str); unlink($filename); } ?> |
以上的程序我已经测试过,只要放在服务器上就可以了,但是该目录要有写的权限。还有一个pkunzip.exe的文件也要放在该目录中,该文件已经放在了压缩包中。
PHP捆绑PDFLIB库也许是最好的web出版平台了。一对典型的用法:
需求小册子
电子商务发货单
通过这个指南,你可以学会怎样使用php教程4中的PDF扩展来创建PDF文档。
我们也把焦点放在用mysql教程数据来创建PDF文档。
内容摘要
安装PDFLib 3.0.1 和有PDF支持的PHP4.01pl2(译注:你可以安装最新的php4.03pl1)
提取PDF文档
(我假设你有一点配置php的经验)
安装PDFLib和有PDF支持的PHP。
需求:
PHP 4.02+ 从 http://php.net 下载
PDFLib 3.0.1 从 http://www.pdflib.com 下载
这是一个怎样让PDFLib3.0.1和php4一起工作的小秘方:(老外很幽默的^_^)
直接从http://www.php.net下载 ext/pdf/pdf.c的补丁来支持PDFLib v 3.0.1
下载PDFLib3.0.1从此处 http://www.pdflib.com
适用的补丁你可以在此找到 http://www.pdflib.com/pdflib/patches.html
配置,Make和安装PDFLib
#./configure --enabled-shared-pdflib
#make
#make install
你会使得 PDFLib 安装在 /usr/local/lib .
配置 PHP
#./configure --with-apxs=/usr/bin/apxs
--with-gd --with-pdflib=/usr/local --with-mysql=/usr/local
--with-config-file-path=/etc/httpd --with-zlib-dir=/usr
--with-ttf=/usr/local/include
--with-jpeg-dir=/usr --with-tiff-dir=/usr
--with-system-regex=yes --enable-debug=no
#make
#make install
更新系统库
插入 /usr/local/lib 进 /etc/ld.so.conf (文件)
#/sbin/ldconfig
测试和验证
现在你需要重启apache
#apachectl restart
拷贝pdfclock.php 到的httpd目录中(就是web目录)...测试....一切正常。
重要信息
要使得PHPLIb和字体一起工作你必须注意PDFLib手册中的UPR部分。
最简单的用PDFLib使用字体的办法是拷贝PDFlib tar包中的标准UPR描述文件(fonts/pdflib.upr)到你的工作目录。
提取PDF文档
现在我们已经作好了如飞地生成PDF文档的条件!
在这个小例子中我们要生成FLYStore公司的需求小册子,当然是从目录数据库教程中提取数据。
准备数据库
我假设你有一点数据库的经验,最小限度,我真的只希望你懂得怎样创建一个数据库并向其中插入表。
创建表 catalogue:
create table catalogue(
id smallint(8) unsigned DEFAULT '0' NOT NULL,
item varchar(100) DEFAULT '' NOT NULL,
description tinytext,
img_data longblob,
imgname varchar(60),
imgsize varchar(60),
imgtype varchar(60),
price smallint(8) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (id),
KEY item (item(20))
);
送出MIME头信息
为了让我们的正确地显示出来,我们需要送出正确的头信息到用户的浏览器。
在PHP中我们可以用header函数实现。下面的代码送出正确的MIME类型到浏览器。
header( "Content-type: application/pdf" );
header( "Content-Disposition: attachment; filename=modulo.pdf" );
header( "Content-Description: PHP3 Generated Data" );
重要信息
你必须知道的是在送出头信息前不能输出任何东西。一个常见的错误是在文件的开头存在空格。
从mysql中取数
这儿我们用一个从目录数据中提数据的简单代码片断。
<?php
$link = mysql_connect ("127.0.0.1", "flyadm", "flystore")
or die ("Could not connect");
mysql_select_db ("flystore", $link);
$result = mysql_query ("SELECT * FROM catalogue", $link)
or die ("Invalid query");
$data = mysql_fetch_row ($result);
....
....
mysql_close ($link);
?>
生成PDF文件
为了生成PDF文档,我们需要作经过以下步骤:
打开一个PDF流,并使它和一个句柄关联:
$pdf = PDF_open();
(Optional) Set document information like Author, Title, Subject, etc
(可选的)设置文档信息,如作者,标题,主题,等
开始一个新页(PDF文件可以用不同的版面生成不同的页,比如肖像,前景...):
PDF_begin_page($pdf, 595, 842);
(可选的)设置一个超链接:
PDF_add_outline($pdf, "Item ".$data[1]);
选择字体类型, 尺寸 (pdf_set_font($pdf, "Helvetica-Bold" , 20, winansi);) 表现模式
插入文本在X.y位置:
PDF_show_xy($pdf, "Item : " .$data[1], 100, 700);
或插入图片在X.Y位置:
pdf_place_image($pdf, $im, 100, 300, 3);
刷新文本缓冲区并关闭PDF流。
PDF Coordinate Systems
What we need to do to locate a string or picture in some part of the PDF page,
在PDF页的很多地方我们需要定位字符串和图片,转换英制单位到DTP点值.
在PDFLIB手册的45页写到:
".. .缺省的坐标系统的原点在页面的左下角,用DTP点作为单位:
1 pt = 1 inch /72 = 25.4mm /72 = 0.3528 mm
"
这儿是生成PDF文件的代码片断:
<?php
$pdf = PDF_open();
pdf_set_info_author($pdf, "Luca Perugini");
PDF_set_info_title($pdf, "Brochure for FlyStore");
pdf_set_info_creator($pdf, "See Author");
pdf_set_info_subject($pdf, "FlyStore");
PDF_begin_page($pdf, 595, 842);
PDF_add_outline($pdf, "Item ".$data[1]);
pdf_set_font($pdf, "Helvetica-Bold" , 20, winansi);
pdf_set_text_rendering($pdf, 0);
pdf_show_xy($pdf, "FlyStore Catalogue 2000",50,780);
PDF_show_xy($pdf, "Item : " .$data[1], 100, 700);
PDF_show_xy($pdf, "Description : " .$data[2], 100, 620);
$im = PDF_open_jpeg($pdf, "pass4_sml.jpg");
pdf_place_image($pdf, $im, 100, 300, 3);
pdf_close_image ($im);
pdf_stroke($pdf);
PDF_end_page($pdf);
PDF_close($pdf);
?>
大多数流行的 Web 服务如 twitter 通过开放 API 来提供数据一样,它总是能够知道如何解析 API 数据的各种传送格式,包括 JSON,XML 等等。
$json_string='{"id":1,"name":"111cn.net","email":"admin@111cn.net","interest":["wordpress","php"]} ';
$obj=json_decode($json_string);
echo $obj->name; //prints foo
echo $obj->interest[1]; //prints php
ecshop解析json类
if (!defined('EC_CHARSET'))
{
define('EC_CHARSET', 'utf-8');
}
class JSON
{
var $at = 0;
var $ch = '';
var $text = '';
function encode($arg, $force = true)
{
static $_force;
if (is_null($_force))
{
$_force = $force;
}
if ($_force && EC_CHARSET == 'utf-8' && function_exists('json_encode'))
{
return json_encode($arg);
}
$returnValue = '';
$c = '';
$i = '';
$l = '';
$s = '';
$v = '';
$numeric = true;
switch (gettype($arg))
{
case 'array':
foreach ($arg AS $i => $v)
{
if (!is_numeric($i))
{
$numeric = false;
break;
}
}
if ($numeric)
{
foreach ($arg AS $i => $v)
{
if (strlen($s) > 0)
{
$s .= ',';
}
$s .= $this->encode($arg[$i]);
}
$returnValue = '[' . $s . ']';
}
else
{
foreach ($arg AS $i => $v)
{
if (strlen($s) > 0)
{
$s .= ',';
}
$s .= $this->encode($i) . ':' . $this->encode($arg[$i]);
}
$returnValue = '{' . $s . '}';
}
break;
case 'object':
foreach (get_object_vars($arg) AS $i => $v)
{
$v = $this->encode($v);
if (strlen($s) > 0)
{
$s .= ',';
}
$s .= $this->encode($i) . ':' . $v;
}
$returnValue = '{' . $s . '}';
break;
case 'integer':
case 'double':
$returnValue = is_numeric($arg) ? (string) $arg : 'null';
break;
case 'string':
$returnValue = '"' . strtr($arg, array(
" " => '\r', " " => '\n', " " => '\t', "" => '\b',
" " => '\f', '\' => '\\', '"' => '"',
"" => 'u0000', "" => 'u0001', "" => 'u0002', "" => 'u0003',
"" => 'u0004', "" => 'u0005', "" => 'u0006', "" => 'u0007',
"" => '', " " => 'u000b', " " => ' ', "" => 'u000e',
"" => 'u000f', "" => 'u0010', "" => 'u0011', "" => 'u0012',
"" => 'u0013', "" => 'u0014', "" => 'u0015', "" => 'u0016',
"" => 'u0017', "" => 'u0018', "" => 'u0019', "" => 'u001a',
"" => 'u001b', "" => 'u001c', "" => 'u001d', "" => 'u001e',
"" => 'u001f'
)) . '"';
break;
case 'boolean':
$returnValue = $arg?'true':'false';
break;
default:
$returnValue = 'null';
}
return $returnValue;
}
function decode($text,$type=0) // 默认type=0返回obj,type=1返回array
{
if (empty($text))
{
return '';
}
elseif (!is_string($text))
{
return false;
}
if (EC_CHARSET === 'utf-8' && function_exists('json_decode'))
{
return $this->addslashes_deep_obj(json_decode(strips教程lashes($text),$type));
}
$this->at = 0;
$this->ch = '';
$this->text = strtr(stripslashes($text), array(
" " => '', " " => '', " " => '', "" => '',
"" => '', "" => '', "" => '', "" => '',
"" => '', "" => '', "" => '', "" => '',
"" => '', " " => '', " " => '', "" => '',
"" => '', "" => '', "" => '', "" => '',
"" => '', "" => '', "" => '', "" => '',
"" => '', "" => '', "" => '', "" => '',
"" => '', "" => '', "" => '', "" => '',
"" => ''
));
$this->next();
$return = $this->val();
$result = empty($type) ? $return : $this->object_to_array($return);
return addslashes_deep_obj($result);
}
/**
* triggers a PHP_ERROR
*
* @access private
* @param string $m error message
*
* @return void
*/
function error($m)
{
trigger_error($m . ' at offset ' . $this->at . ': ' . $this->text, E_USER_ERROR);
}
/**
* returns the next character of a JSON string
*
* @access private
*
* @return string
*/
function next()
{
$this->ch = !isset($this->text{$this->at}) ? '' : $this->text{$this->at};
$this->at++;
return $this->ch;
}
/**
* handles strings
*
* @access private
*
* @return void
*/
function str()
{
$i = '';
$s = '';
$t = '';
$u = '';
if ($this->ch == '"')
{
while ($this->next() !== null)
{
if ($this->ch == '"')
{
$this->next();
return $s;
}
elseif ($this->ch == '\')
{
switch ($this->next())
{
case 'b':
$s .= '';
break;
case 'f':
$s .= ' ';
break;
case 'n':
$s .= ' ';
break;
case 'r':
$s .= ' ';
break;
case 't':
$s .= ' ';
break;
case 'u':
$u = 0;
for ($i = 0; $i < 4; $i++)
{
$t = (integer) sprintf('%01c', hexdec($this->next()));
if (!is_numeric($t))
{
break 2;
}
$u = $u * 16 + $t;
}
$s .= chr($u);
break;
case ''':
$s .= ''';
break;
default:
$s .= $this->ch;
}
}
else
{
$s .= $this->ch;
}
}
}
$this->error('Bad string');
}
/**
* handless arrays
*
* @access private
*
* @return void
*/
function arr()
{
$a = array();
if ($this->ch == '[')
{
$this->next();
if ($this->ch == ']')
{
$this->next();
return $a;
}
while (isset($this->ch))
{
array_push($a, $this->val());
if ($this->ch == ']')
{
$this->next();
return $a;
}
elseif ($this->ch != ',')
{
break;
}
$this->next();
}
$this->error('Bad array');
}
}
/**
* handles objects
*
* @access public
*
* @return void
*/
function obj()
{
$k = '';
$o = new StdClass();
if ($this->ch == '{')
{
$this->next();
if ($this->ch == '}')
{
$this->next();
return $o;
}
while ($this->ch)
{
$k = $this->str();
if ($this->ch != ':')
{
break;
}
$this->next();
$o->$k = $this->val();
if ($this->ch == '}')
{
$this->next();
return $o;
}
elseif ($this->ch != ',')
{
break;
}
$this->next();
}
}
$this->error('Bad object');
}
/**
* handles objects
*
* @access public
*
* @return void
*/
function assoc()
{
$k = '';
$a = array();
if ($this->ch == '<')
{
$this->next();
if ($this->ch == '>')
{
$this->next();
return $a;
}
while ($this->ch)
{
$k = $this->str();
if ($this->ch != ':')
{
break;
}
$this->next();
$a[$k] = $this->val();
if ($this->ch == '>')
{
$this->next();
return $a;
}
elseif ($this->ch != ',')
{
break;
}
$this->next();
}
}
$this->error('Bad associative array');
}
/**
* handles numbers
*
* @access private
*
* @return void
*/
function num()
{
$n = '';
$v = '';
if ($this->ch == '-')
{
$n = '-';
$this->next();
}
while ($this->ch >= '0' && $this->ch <= '9')
{
$n .= $this->ch;
$this->next();
}
if ($this->ch == '.')
{
$n .= '.';
while ($this->next() && $this->ch >= '0' && $this->ch <= '9')
{
$n .= $this->ch;
}
}
if ($this->ch == 'e' || $this->ch == 'E')
{
$n .= 'e';
$this->next();
if ($this->ch == '-' || $this->ch == '+')
{
$n .= $this->ch;
$this->next();
}
while ($this->ch >= '0' && $this->ch <= '9')
{
$n .= $this->ch;
$this->next();
}
}
$v += $n;
if (!is_numeric($v))
{
$this->error('Bad number');
}
else
{
return $v;
}
}
/**
* handles words
*
* @access private
*
* @return mixed
*/
function word()
{
switch ($this->ch)
{
case 't':
if ($this->next() == 'r' && $this->next() == 'u' && $this->next() == 'e')
{
$this->next();
return true;
}
break;
case 'f':
if ($this->next() == 'a' && $this->next() == 'l' && $this->next() == 's' && $this->next() == 'e')
{
$this->next();
return false;
}
break;
case 'n':
if ($this->next() == 'u' && $this->next() == 'l' && $this->next() == 'l')
{
$this->next();
return null;
}
break;
}
$this->error('Syntax error');
}
/**
* generic value handler
*
* @access private
*
* @return mixed
*/
function val()
{
switch ($this->ch)
{
case '{':
return $this->obj();
case '[':
return $this->arr();
case '<':
return $this->assoc();
case '"':
return $this->str();
case '-':
return $this->num();
default:
return ($this->ch >= '0' && $this->ch <= '9') ? $this->num() : $this->word();
}
}
/**
* Gets the properties of the given object recursion
*
* @access private
*
* @return array
*/
function object_to_array($obj)
{
$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($_arr as $key => $val)
{
$val = (is_array($val) || is_object($val)) ? $this->object_to_array($val) : $val;
$arr[$key] = $val;
}
return $arr;
}
/**
* 递归方式的对变量中的特殊字符进行转义
*
* @access public
* @param mix $value
*
* @return mix
*/
function addslashes_deep($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}
}
/**
* 将对象成员变量或者数组的特殊字符进行转义
*
* @access public
* @param mix $obj 对象或者数组
* @author Xuan Yan
*
* @return mix 对象或者数组
*/
function addslashes_deep_obj($obj)
{
if (is_object($obj) == true)
{
foreach ($obj AS $key => $val)
{
$obj->$key =$this-> addslashes_deep($val);
}
}
else
{
$obj = addslashes_deep($obj);
}
return $obj;
}
/**
* 递归方式的对变量中的特殊字符去除转义
*
* @access public
* @param mix $value
*
* @return mix
*/
function stripslashes_deep($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
}
}
/**
* 将JSON传递的参数转码
*
* @param string $str
* @return string
*/
function json_str_iconv($str)
{
if (EC_CHARSET != 'utf-8')
{
if (is_string($str))
{
return ecs_iconv('utf-8', EC_CHARSET, $str);
}
elseif (is_array($str))
{
foreach ($str as $key => $value)
{
$str[$key] = json_str_iconv($value);
}
return $str;
}
elseif (is_object($str))
{
foreach ($str as $key => $value)
{
$str->$key = json_str_iconv($value);
}
return $str;
}
else
{
return $str;
}
}
return $str;
}
}
$string='{"email":"cc@126.com","content":"this is a just a test","type":"0","id":"13","enabled_captcha":"0","captcha":"","rank":"5"}';
$json=new JSON();
$cmt = $json->json_str_iconv($string); //字符转码
$cmt = $json->decode($cmt); //解码
print_r($cmt);
相关文章
- 下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
- eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
- 在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
Jupyter Notebook读取csv文件出现的问题及解决
这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06Python astype(np.float)函数使用方法解析
这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08- 这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
- 本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
- 下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- 有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
- 这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
- 这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
- C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
php无刷新利用iframe实现页面无刷新上传文件(1/2)
利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25- CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
- 本文章来人大家介绍一个php文件上传类的使用方法,期望此实例对各位php入门者会有不小帮助哦。 简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮...2016-11-25
Android开发中findViewById()函数用法与简化
findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20- 要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
- 又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
- 这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18