通过PHP的File函数库来完成上传图像文件并让其显示_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了通过PHP的File函数库来完成上传图像文件并让其显示_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2403字,纯文字阅读大概需要4分钟。
内容图文
![通过PHP的File函数库来完成上传图像文件并让其显示_PHP教程](/upload/InfoBanner/zyjiaocheng/179/dec204d031744b47b53595eb41df2dfd.jpg)
$filepath = "/home/httpd/html/tut/upload";
// 200K is the maximum (picture) file size to be accepted
define("MAX_FILE_SIZE", 200*1024);
function print_error ($err) {
echo "
$err
";
}
do {
// check if picture name variable has a value; if not, skip to the
// "while(false)" section of "do" statement
if(isset($picture)) {
// here is where the server transparently checks that the client picture file
// doesn't exceed maximum allowable size
if(getenv("CONTENT_LENGTH") > MAX_FILE_SIZE) {
print_error("File too large: $picture_name");
break;
}
// open client picture file for read only; "@" prefix tells fopen not to print
// message if there is an error, since function print_error does that
// if there is an error, break out of "do" loop and continue at "while(false)"
$fp = @fopen($picture,"r");
if(!$fp) {
print_error("Cannot open file: $picture_name");
break;
}
// generate unique name for session, use it to generate unique server
// directory name, and create the directory
srand((double) microtime() * 1000000);
$id = md5(uniqid(rand()));
$dirname = "$filepath/$id";
mkdir($dirname,0700);
// create the server picture file in the newly created server directory
$filename = $dirname . "/picture";
// open server picture file for write only; "@" prefix tells fopen not to
// print message if there is an error, since function print_error does that
// if there is an error, break out of "do" loop and continue at "while(false)"
$out = @fopen($filename,"w");
if(!$out) {
print_error("Cannot open file: $filename");
break;
}
// copy client picture file to server picture file
while($buffer = fread($fp,8192)) {
fwrite($out,$buffer);
}
// close client picture file and server picture file
fclose($fp);
fclose($out);
// create server name file in picture file directory; this file will hold the
// name of the picture file
$filename = $dirname . "/name";
// open server name file for write only; "@" prefix tells fopen not to print
// message if there is an error, since function print_error does that
// if there is an error, break out of "do" loop and continue at "while(false)"
$out = @fopen($filename,"w");
http://www.bkjia.com/PHPjc/631407.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631407.htmlTechArticle?php // full directory path $filepath = /home/httpd/html/tut/upload; // 200K is the maximum (picture) file size to be accepted define(MAX_FILE_SIZE, 200*1024); function print_error...
内容总结
以上是互联网集市为您收集整理的通过PHP的File函数库来完成上传图像文件并让其显示_PHP教程全部内容,希望文章能够帮你解决通过PHP的File函数库来完成上传图像文件并让其显示_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。