像discuz发帖那样,一次上传多个图片,然后将所有上传的图片路径插入到编辑器中。
有没有?
回复讨论(解决方案)
找个JS批量上传插件,主要是美观而已,技术角度还是个表单。
从http协议实现角度,下面的php代码是一个活生生的协议细节:
<?php function do_post_request($url, $postdata, $files = null) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10); //Collect Postdata foreach($postdata as $key => $val) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } $data .= "--$boundary\n"; //Collect Filedata foreach($files as $key => $file) { $fileContents = file_get_contents($file['tmp_name']); $data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\n"; $data .= "Content-Type: image/jpeg\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $fileContents."\n"; $data .= "--$boundary--\n"; } $params = array('http' => array( 'method' => 'POST', 'header' => 'Content-Type: multipart/form-data; boundary='.$boundary, 'content' => $data )); $ctx = stream_context_create($params); $fp = fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } //set data (in this example from post) //sample data $postdata = array( 'name' => $_POST['name'], 'age' => $_POST['age'], 'sex' => $_POST['sex'] ); //sample image $files['image'] = $_FILES['image']; do_post_request("http://example.com", $postdata, $files); ?>
swfopload
在学习PHP中可能会遇到PHP上传多张图片问题,上传图片需要对图片格式的校验,保证上传的一定是图片,防止上传其他文件到服务器。多图片上传基本实现方法是使用数组的形式,把所有的图片提交个一个数组,对数组的元素进行一个个循环的处理。下面是PHP多图片上传的代码示例:
1. 2.//图片目录
3.$img_dir="../upload/";
4.//……html显示上传界面
5./*图片上传处理*/
6.//把图片传到服务器
7.//初始化变量
8.$uploaded=0;
9.$unuploaded=0;
10.//只允许五张图片上传
11.for($i=0;$i 12.{
13.//获取当前图片的信息
14.$is_file=$_FILES['imgfile']['name'][$i];
15.//如果当前图片不为空
16.if(!empty($is_file))
17.{
18.//把当前图片的信息存储到变量里
19.$result[$i]="
20.
21.
22.
23.
24.
25.//判断上传的图片的类型是不是jpg,gif,png,bmp中的一种,同时判断是否上传成功
26.if(
27.$_FILES['imgfile']['type'][$i]=="image/pjpeg"||
28.$_FILES['imgfile']['type'][$i]=="image/gif"||
29.$_FILES['imgfile']['type'][$i]=="image/x-png"||
30.$_FILES['imgfile']['type'][$i]=="image/bmp"
31.)
32.{
33.//如果上传的文件没有在服务器上存在
34.if(!file_exists($img_dir.$_FILES['imgfile']['name'][$i]))
35.{
36.//把图片文件从临时文件夹中转移到我们指定上传的目录中
37.move_uploaded_file($_FILES['imgfile']['tmp_name'][$i],
38.$img_dir.$_FILES['imgfile']['name'][$i]);
39.$result[$i].="成功";
40.$uploaded++;
41.}
42.else//如果文件已经在服务器上存在
43.{
44.$result[$i].="
45.$unuploaded++;
46.continue;
47.}
48.}
49.else
50.{
51.$result[$i].="
52.$unuploaded++;
53.}
54.$result[$i].="
55.}//endif
56.}//endfor
57.//如果没有选择任何图片
58.if(empty($result))
59.{
60.prompt_msg("错误信息","没有选择任何图片。","返回上一步","uploadimg.php?action=upload");
61.exit();
62.}
63.//显示所有上传后的结果
引用楼主 的回复:
像discuz发帖那样,一次上传多个图片,然后将所有上传的图片路径插入到编辑器中。
有没有?
网上有一个仿QQ相册上传插件的程序。
Xproer.ImageUploader: http://www.cnblogs.com/xproer/archive/2010/08/09/1796077.html
主界面
图片列表
添加图片
编辑图片:
提示信息:
这个强,我们公司上次给客户做的一个网站也是用的这个WEB图片上传控件。
引用楼主 的回复:
像discuz发帖那样,一次上传多个图片,然后将所有上传的图片路径插入到编辑器中。
有没有?
网上有一个仿QQ相册上传插件的程序。
Xproer.ImageUploader: http://www.cnblogs.com/xproer/archive/2010/08/09/1796077.html
主界面
图片列表
添加图片
编辑图片:
提示信息:
这个用户体验不错。现在的互联网产品做的也越来越好了,用户使用起来也越来越方便了。
引用楼主 的回复:
像discuz发帖那样,一次上传多个图片,然后将所有上传的图片路径插入到编辑器中。
有没有?
网上有一个仿QQ相册上传插件的程序。
Web图片批量上传控件(Xproer.ImageUploader): http://www.cnblogs.com/xproer/archive/2010/08/09/1796077.html
主界面
图片列表
添加图片
编辑图片:
提示信息:
整合代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Web图片批量上传控件演示页面</title> <script type="text/javascript" src="ImageUploader/ImageUploader.js" charset="utf-8"></script></head><body> <div><a href="asp.net/images.aspx">查看上传的图片</a></div> <div id="msg"></div> <script language="javascript" type="text/javascript"> var imgUploader = new ImageUploader(); imgUploader.Config["PostUrl"] = "http://localhost/php/upload.php"; window.onload = function() { imgUploader.Init(); } </script></body></html>
这个真心牛X~!!~收下鸟。刚接了一个做网站的单子,正好用上。~!
我去,4楼的那个插件大家别用!!!!!!!!!!!!!!!
本地可以使用,但是项目放到互联网使用时,就会提示你IP未授权,不让你继续使用,原来这插件是个收费版的!!!而且价钱还不是一般的贵!!!我瞎了眼了,下下来之后自己改了好多代码才弄好的图片上传,放到网上去之后就用不起来了!!!为什么用的时候不告诉我是收费的!!!这个公司就是贱!!!不让用拉倒,去别别的插件用!!!
我去,4楼的那个插件大家别用!!!!!!!!!!!!!!!
本地可以使用,但是项目放到互联网使用时,就会提示你IP未授权,不让你继续使用,原来这插件是个收费版的!!!而且价钱还不是一般的贵!!!我瞎了眼了,下下来之后自己改了好多代码才弄好的图片上传,放到网上去之后就用不起来了!!!为什么用的时候不告诉我是收费的!!!这个公司就是贱!!!不让用拉倒,去别别的插件用!!!
其实收费还可以理解。问题是这也太贵了。我也是改了很多代码,好不容易和自己的站点融合了,放到服务器上,提示未授权,问了该公司客服,才知道要收费的。真坑。

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version