想通过客户端文件来提取特征码,上传有点问题,昨晚今早终于搞定了。
首先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
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); } ?> |
阅读(2377) | 评论(0) | 转发(0) |