好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>CMS系统>Dedecms
<tfoot draggable='sEl'></tfoot>

phppost上传图片 php上传图片大小限制

很多站长朋友们都不太清楚phppost上传图片,今天小编就来给大家整理phppost上传图片,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 php上传图片的问题! 2、 php 模拟post 上传 3、 thinkphp的框架 怎么能实现图片上传功能和写入数据库,form 这样定义之后 post获取不到img_url值 4、 怎样用PHP实现文件上传 5、 PHP做一个网页 支持用户上传图片并显示的 如何实现 6、 Thinkphp 中的 ueditor 上传图片的post地址如何修改! 在线等 php上传图片的问题!

首先在php的目录下,建一个images的文件夹

把以代码另存为upload.php

<form name="newad" method="post" enctype="multipart/form-data" action="">

<table>

<tr><td><input type="file" name="image" ></td></tr>

<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>

</table>

</form>PHP Code

<?php

//define a maxim size for the uploaded images

define ("MAX_SIZE","10000000");

// define the width and height for the thumbnail

// note that theese dimmensions are considered the maximum dimmension and are not fixed,

// because we have to keep the image ratio intact or it will be deformed

define ("WIDTH","170");

define ("HEIGHT","120");

// this is the function that will create the thumbnail image from the uploaded image

// the resize will be done considering the width and height defined, but without deforming the image

function make_thumb($img_name,$filename,$new_w,$new_h)

{

//get image extension.

$ext=getExtension($img_name);

//creates the new image using the appropriate function from gd library

if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))

$src_img=imagecreatefromjpeg($img_name);

if(!strcmp("png",$ext))

$src_img=imagecreatefrompng($img_name);

//gets the dimmensions of the image

$old_x=imageSX($src_img);

$old_y=imageSY($src_img);

// next we will calculate the new dimmensions for the thumbnail image

// the next steps will be taken:

// 1. calculate the ratio by dividing the old dimmensions with the new ones

// 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable

// and the height will be calculated so the image ratio will not change

// 3. otherwise we will use the height ratio for the image

// as a result, only one of the dimmensions will be from the fixed ones

$ratio1=$old_x/$new_w;

$ratio2=$old_y/$new_h;

if($ratio1>$ratio2) {

$thumb_w=$new_w;

$thumb_h=$old_y/$ratio1;

}

else {

$thumb_h=$new_h;

$thumb_w=$old_x/$ratio2;

}

// we create a new image with the new dimmensions

$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

// resize the big image to the new created one

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

// output the created image to the file. Now we will have the thumbnail into the file named by $filename

if(!strcmp("png",$ext))

imagepng($dst_img,$filename);

else

imagejpeg($dst_img,$filename);

//destroys source and destination images.

imagedestroy($dst_img);

imagedestroy($src_img);

}

// This function reads the extension of the file.

// It is used to determine if the file is an image by checking the extension.

function getExtension($str) {

$i = strrpos($str,".");

if (!$i) { return ""; }

$l = strlen($str) - $i;

$ext = substr($str,$i+1,$l);

return $ext;

}

// This variable is used as a flag. The value is initialized with 0 (meaning no error found)

//and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded.

$errors=0;

// checks if the form has been submitted

if(isset($_POST['Submit']))

{

//reads the name of the file the user submitted for uploading

$image=$_FILES['image']['name'];

// if it is not empty

if ($image)

{

// get the original name of the file from the clients machine

$filename = stripslashes($_FILES['image']['name']);

// get the extension of the file in a lower case format

$extension = getExtension($filename);

$extension = strtolower($extension);

// if it is not a known extension, we will suppose it is an error, print an error message

//and will not upload the file, otherwise we continue

if (($extension != "jpg") ($extension != "jpeg") ($extension != "png"))

{

echo '<h1>Unknown extension!</h1>';

$errors=1;

}

else

{

// get the size of the image in bytes

// $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server

$size=getimagesize($_FILES['image']['tmp_name']);

$sizekb=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger

if ($sizekb > MAX_SIZE*1024)

{

echo '<h1>You have exceeded the size limit!</h1>';

$errors=1;

}

//we will give an unique name, for example the time in unix time format

$image_name=time().'.'.$extension;

//the new name will be containing the full path where will be stored (images folder)

$newname="images/".$image_name;

$copied = copy($_FILES['image']['tmp_name'], $newname);

//we verify if the image has been uploaded, and print error instead

if (!$copied)

{

echo '<h1>Copy unsuccessfull!</h1>';

$errors=1;

}

else

{

// the new thumbnail image will be placed in images/thumbs/ folder

$thumb_name='images/'.$image_name;

// call the function that will create the thumbnail. The function will get as parameters

//the image name, the thumbnail name and the width and height desired for the thumbnail

$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);

}} }}

//If no errors registred, print the success message and show the thumbnail image created

if(isset($_POST['Submit']) !$errors)

{

echo "<h1>Thumbnail created Successfully!</h1>";

echo '<img src="'.$thumb_name.'">';

}

?>

php 模拟post 上传

你写一个方法把,在php里面可以使用curl库来模拟这样的表单 代码如下:

//curl实现post请求

public function curl_post($url, $data = null){

//创建一个新cURL资源

$curl = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 跳过证书检查

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在

//设置URL和相应的选项

curl_setopt($curl, CURLOPT_URL, $url);

if (!empty($data)){

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

}

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

//执行curl,抓取URL并把它传递给浏览器

$output = curl_exec($curl);

//关闭cURL资源,并且释放系统资源

curl_close($curl);

return $output;

}

thinkphp的框架 怎么能实现图片上传功能和写入数据库,form 这样定义之后 post获取不到img_url值

思路是可以的,那提交数据后image可以获取吗?如果可以,那肯定是填写链接的input有问题,而且你下面的图有两个图片和链接,说明你是点了"点击添加多个图片"那个操作,那个操作之后新建的html一样?如果一样就会有两个'img_url'和'image'input标签,你应该用'img_url[]' 和 'image[]',大概想到这些

怎样用PHP实现文件上传

创建一个文件上传表单

允许用户从表单上传文件是非常有用的。

请看下面这个供上传文件的 HTML 表单:

<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>

请留意如下有关此表单的信息:

<form> 标签的 enctype 属性规定了在提交表单时要使用哪种内容类型。在表单需要二进制数据时,比如文件内容,请使用 "multipart/form-data"。

<input> 标签的 type="file" 属性规定了应该把输入作为文件来处理。举例来说,当在浏览器中预览时,会看到输入框旁边有一个浏览按钮。

注释:允许用户上传文件是一个巨大的安全风险。请仅仅允许可信的用户执行文件上传操作。

创建上传脚本

"upload_file.php" 文件含有供上传文件的代码:

<?php

if ($_FILES["file"]["error"] > 0)

{

echo "Error: " . $_FILES["file"]["error"] . "<br />";

}

else

{

echo "Upload: " . $_FILES["file"]["name"] . "<br />";

echo "Type: " . $_FILES["file"]["type"] . "<br />";

echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

echo "Stored in: " . $_FILES["file"]["tmp_name"];

}

?>

通过使用 PHP 的全局数组 $_FILES,你可以从客户计算机向远程服务器上传文件。

第一个参数是表单的 input name,第二个下标可以是 "name", "type", "size", "tmp_name" 或 "error"。就像这样:

$_FILES["file"]["name"] - 被上传文件的名称

$_FILES["file"]["type"] - 被上传文件的类型

$_FILES["file"]["size"] - 被上传文件的大小,以字节计

$_FILES["file"]["tmp_name"] - 存储在服务器的文件的临时副本的名称

$_FILES["file"]["error"] - 由文件上传导致的错误代码

这是一种非常简单文件上传方式。基于安全方面的考虑,您应当增加有关什么用户有权上传文件的限制。

上传限制

在这个脚本中,我们增加了对文件上传的限制。用户只能上传 .gif 或 .jpeg 文件,文件大小必须小于 20 kb:

<?php

if ((($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg"))

($_FILES["file"]["size"] < 20000))

{

if ($_FILES["file"]["error"] > 0)

{

echo "Error: " . $_FILES["file"]["error"] . "<br />";

}

else

{

echo "Upload: " . $_FILES["file"]["name"] . "<br />";

echo "Type: " . $_FILES["file"]["type"] . "<br />";

echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

echo "Stored in: " . $_FILES["file"]["tmp_name"];

}

}

else

{

echo "Invalid file";

}

?>

注释:对于 IE,识别 jpg 文件的类型必须是 pjpeg,对于 FireFox,必须是 jpeg。

保存被上传的文件

上面的例子在服务器的 PHP 临时文件夹创建了一个被上传文件的临时副本。

这个临时的复制文件会在脚本结束时消失。要保存被上传的文件,我们需要把它拷贝到另外的位置:

<?php

if ((($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/pjpeg"))

($_FILES["file"]["size"] < 20000))

{

if ($_FILES["file"]["error"] > 0)

{

echo "Return Code: " . $_FILES["file"]["error"] . "<br />";

}

else

{

echo "Upload: " . $_FILES["file"]["name"] . "<br />";

echo "Type: " . $_FILES["file"]["type"] . "<br />";

echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";

echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))

{

echo $_FILES["file"]["name"] . " already exists. ";

}

else

{

move_uploaded_file($_FILES["file"]["tmp_name"],

"upload/" . $_FILES["file"]["name"]);

echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

}

}

}

else

{

echo "Invalid file";

}

?>

上面的脚本检测了是否已存在此文件,如果不存在,则把文件拷贝到指定的文件夹。

注释:这个例子把文件保存到了名为 "upload" 的新文件夹。

PHP做一个网页 支持用户上传图片并显示的 如何实现

前台:

<form action="php_insertpic.php" method="post" enctype="multipart/form-data" >

<input type="file" name="myFile" id="myFile" />

</form>

后台:

$pic_data = $_FILES["myFile"]["tmp_name"];

$pic_size = $_FILES["myFile"]["size"];

$filepic = addslashes(fread(fopen($pic_data, "rb"), $pic_size ));

后面再加上插入数据库的语句就可以了,如:"insert into pic(id,picture) values(1,$filepic)"

显示图片:

header("Content-type:image/jpeg");

连接数据库

$result=mysql_query("select * from pic where id=1");

$myrow=mysql_fetch_array($result);

echo ($myrow["picture"]);

Thinkphp 中的 ueditor 上传图片的post地址如何修改! 在线等

找到这个 ueditor.config.js

修改大约 136 137行 :图片上传提交地址和图片修正地址

,imageUrl:URL+"php/imageUp.php"    //图片上传提交地址

,imagePath:"/"                     //图片修正地址,引用了fixedImagePath,如有特殊需求,可自行配置

下一步是找到这个 imageUp.php 文件

修改代码:

//上传配置

    $config = array(

        "savePath" => ($path == "1" ? "Uploads" : "Uploads"),

        "maxSize" => 1000, //单位KB

        "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")

    );

其中 “Uploads” 这个是你的这个imageUp.php文件所要返回站点根目录的层级,“Uploads”代表 根目录Uploads文件夹。

我把我怕自己的路径贴给你看下,你自己适当的修改一下就可以:

我的根目录是:htdocs  所有文件和文件夹夹都放在这个文件夹下;

修改的第一个文件:htdocs\Public\ueditor\ueditor.config.js

修改的第二个文件:htdocs\Public\ueditor\php\imageUp.php

上传的图片放置的位置:htdocs\Uploads\

关于phppost上传图片的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于phppost上传图片 php上传图片大小限制的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did167765
更新时间:2023-03-31   阅读:24次

上一篇: php定义xml数据 php处理xml数据

下一篇:php修改api php修改apk包名以及logo

相关资讯

最新资料更新

  • 1.DedeCms autoindex和itemindex使用介绍
  • 2.织梦在导航栏下拉菜单中调用当前栏目子类的方法
  • 3.dedecms列表不显示第一个元素如分隔符的简单方法
  • 4.dedecms 的cn_substr_utf8字符串截取函数商榷
  • 5.Dede中通过SQL调用简略标题shorttitle和链接地址的方法
  • 6.DEDECMS相关文章以关键字相关的修改方法(自定义函数)
  • 7.dedecms 分页标题提取方法
  • 8.dedecms织梦实现中英文分页功能方法步骤
  • 9.dedecms首页调用专题页描述和链接的实现方法
  • 10.织梦DEDECMS网站栏目页获取当前顶级栏目名称的标签
  • 11.dedecms后台添加栏目图片的实现代码
  • 12.浅析DedeCMS GBK版安装sphinx全文索引无法查询无结果的解决方法
  • 13.dedecms获取当前所在栏目ID的方法
  • 14.dedecms列表页标题title后加上页数其标题不重复的方法
  • 15.dedecms文章页上一篇与下一篇标题长度截取的方法
  • 16.不用注册会员也能为DedeCms增加邮箱订阅的方法
  • 17.织梦dedecms获取上一篇下一篇文章链接的方法
  • 18.dedecms5.7后台发布文章提示“标题不能为空”的解决方法
  • 19.DEDECMS会员信息在个人模板info和index的调用问题
  • 20.织梦DEDECMS后台验证码错误不能正常验证的3种可能原因和解决方法

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]