使用$.post提交表格时,图片是无法上传的(除非用编辑器插件什么的,那些都比较大)。
这是一个新思路,图片转base64编码,提交上去,当然,图片不能太大,超过上传限制是不行的。function base64_upload($base64) {<br>
$base64_image = str_replace(' ', '+', $base64);<br>
//post的数据里面,加号会被替换为空格,需要重新替换回来,如果不是post的数据,则注释掉这一行<br>
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image, $result)){<br>
//匹配成功<br>
if($result[2] == 'jpeg'){<br>
$image_name = uniqid().'.jpg';<br>
//纯粹是看jpeg不爽才替换的<br>
}else{<br>
$image_name = uniqid().'.'.$result[2];<br>
}<br>
$image_file = "./upload/test/{$image_name}";<br>
//服务器文件存储路径<br>
if (file_put_contents($image_file, base64_decode(str_replace($result[1], '', $base64_image)))){<br>
return $image_name;<br>
}else{<br>
return false;<br>
}<br>
}else{<br>
return false;<br>
}<br>
}
AD:真正免费,域名+虚机+企业邮箱=0元

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software