Chinaunix首页 | 论坛 | 博客
  • 博客访问: 310862
  • 博文数量: 42
  • 博客积分: 2718
  • 博客等级: 少校
  • 技术积分: 467
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-19 10:23
个人简介

青 田 酒 店 服 务 小 姐 价 格 186-6531-7773

文章分类

全部博文(42)

文章存档

2011年(36)

2010年(6)

分类: 系统运维

2010-11-24 07:48:34

想通过客户端文件来提取特征码,上传有点问题,昨晚今早终于搞定了。
首先php.ini中设置:
file_uploads = On
upload_max_filesize = 50M
把文件临时目录设置为:
upload_tmp_dir = "/usr/local/cme/web/cme/tmp"
然后就ok了
代码段写法参考这样的。
 

<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>


Notice the following about the HTML form above:

  • The enctype attribute of the
    tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data, like the contents of a file, to be uploaded
  • The type="file" attribute of the tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field

form的enctype="multipart/form-data"一定加上。

然后想把最终文件存放到/usr/local/cme/web/cme/upload下,因此两个目录都要设置权限。

chmod 777 upload

chmod 777 tmp

介样就OK了

 

if ($_POST['btAdd'])
{
        $name = $_POST['txtName'];
        $task = $_POST['txtTaskName'];
        $type = $_POST['selectType'];
        $md5 = $_POST['txtFile'];
        ////////////////////
        $oldname = $_FILES['txtFile']['name'];
        $attach = $_FILES['txtFile']['tmp_name'];
        $error = $_FILES['txtFile']['error'];
        $size = $_FILES['txtFile']['size'];

        $newname = "/usr/local/cme/web/cme/upload/".basename($oldname);
        if (!move_uploaded_file($attach, $newname))
        {
                die ("upload file failed\n");
        }

         if ($size/1024/1024 > 10)
         {
                die ("上传文件大小不能超过10M");
         }

        ///////////////////
        //$ret = add_taskrule($cme_db, $name, $task, $type, $md5);
        $ret = add_taskrule($cme_db, $name, $task, $type, $newname);

?>


阅读(2382) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~