search
HomeBackend DevelopmentPHP TutorialPHP5 image upload code, date folder, random file name_PHP tutorial
PHP5 image upload code, date folder, random file name_PHP tutorialJul 13, 2016 pm 05:37 PM
enctypeformmultipartphp5uploadcodepicturefile namefolderdaterandom

index.htm



 



upload.php


$f=$_FILES[jeff_img_upload];

//Judge whether the file has been uploaded
if ($f[error]==4){
echo("<script>alert(Please select the file you want to upload, thank you!);location.href=index.htm;</script>");
}
else{
//Error judgment
if ($f[error]){
echo "Failed, the file is too large! The error code is".$f[error];
exit;
}

//Type judgment
if (substr($f[type], 0, 5) == image) {
switch ($f[type]) {
case image/jpeg:
case image/jpg:
case image/pjpeg:
$ext = .jpg;
break;
case image/gif:
$ext = .gif;
break;
case image/png:
case image/x-png:
$ext = .png;
break;
                                                                                                                                                                                                               default:
header(Content-type: text/html; charset=UTF-8);
                                                                                                                                            with with echo("<script>alert(you didn’t upload a picture, right?);location.href=index.htm;< /script>");<br /> die(REDIRECTING...);<br /> break;<br />                  }<br /> }else {<br /> header(Content-type: text/html; charset=UTF-8);<br /> Echo ("" & lt; script & gt; alert (are you passing by the picture?); Local die(REDIRECTING...);<br />                 }<br /> <br />//Generate random numbers<br /> $randomnum=NULL;<br /> for($j=0;$j<=5;$j++)//The length of the random number. In this example, the length of the random number is 6<br /> {<br /> srand((double)microtime()*1000000);<br /> $randomnumber=rand(!$j ? 1: 0,9);//Generate random numbers, not 0 as the first number, there are some special places where the beginning of 0 is omitted by the system<br /> $randomnum.=$randomnumber;<br /> }<br /> <br /> <br /> $dest_dir=/var/www/htdocs/upload;//Set the upload directory<br /> <br /> //Generate date directory. First determine whether the date directory exists, if not, create it. <br /> if(!file_exists(date("Ymd"))){<br /> mkdir(date("Ymd"),0777);}<br /> <br /> <br /> $dest=$dest_dir./.date("Ymd")./.time()._.$randomnum.$ext;//Set the file name with a timestamp plus a random number to avoid duplication<br /> $r=move_uploaded_file($f[tmp_name],$dest);<br /> chmod($dest, 0777);//Set the attributes of the uploaded file<br /> }<br /> echo "Successful, the file address is: ".$dest;<br /> ?> <p align="left"><div style="display:none;"><span id="url" itemprop="url">http://www.bkjia.com/PHPjc/486550.html<span id="indexUrl" itemprop="indexUrl">www.bkjia.com<span id="isOriginal" itemprop="isOriginal">true<span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/486550.html<span id="genre" itemprop="genre">TechArticle<span id="description" itemprop="description">index.htm form enctype=multipart/form-data action=upload.php method=post input type=hidden name =MAX_FILE_SIZE value=2000000 input name=userfile type=file input type=submit value=Upload... <div class="art_confoot"></script>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php5和php8有什么区别php5和php8有什么区别Sep 25, 2023 pm 01:34 PM

php5和php8的区别在性能、语言结构、类型系统、错误处理、异步编程、标准库函数和安全性等方面。详细介绍:1、性能提升,PHP8相对于PHP5来说在性能方面有了巨大的提升,PHP8引入了JIT编译器,可以对一些高频执行的代码进行编译和优化,从而提高运行速度;2、语言结构改进,PHP8引入了一些新的语言结构和功能,PHP8支持命名参数,允许开发者通过参数名而不是参数顺序等等。

超简单!用 Python 为图片和 PDF 去掉水印超简单!用 Python 为图片和 PDF 去掉水印Apr 12, 2023 pm 11:43 PM

网上下载的 pdf 学习资料有一些会带有水印,非常影响阅读。比如下面的图片就是在 pdf 文件上截取出来的,今天我们就来用Python解决这个问题。安装模块PIL:Python Imaging Library 是 python 上非常强大的图像处理标准库,但是只能支持 python 2.7,于是就有志愿者在 PIL 的基础上创建了支持 python 3的 pillow,并加入了一些新的特性。pip install pillow pymupdf 可以用 python 访问扩展名为*.pdf、

PS AI修图免费平替来了!Stability AI又放大招,核弹级更新一键扩图PS AI修图免费平替来了!Stability AI又放大招,核弹级更新一键扩图Jun 12, 2023 pm 07:27 PM

此前,PS的重建图像功能就让人无比振奋,让无数人惊呼今天,StabilityAI又放大招了。它联合Clipdrop推出了UncropClipdrop——一个终极图像比例编辑器。从Uncrop这个名字上,我们就能看出它的用途。它是一个AI生成的「外画」工具,通过创建扩展背景,这个工具可以补充任何现有照片或图像,来更改任何图像的比例。敲黑板:通过Clipdrop网站,就可以免费试用这个工具了,无需登录!比例任意调,满意为止Uncrop基于StabilityAI的文本到图像模型StableDiffus

如何使用 Vue 实现图片预加载?如何使用 Vue 实现图片预加载?Jun 25, 2023 am 11:01 AM

在网页开发中,图片预载是一种常见的技术,可以提升用户的体验感。当用户浏览网页时,图片可以提前下载并加载,减少图片加载时的等待时间。在Vue框架中,我们可以通过一些简单的方法来实现图片预载。本文将介绍Vue中的图片预载技术,包括预载的原理、实现的方法和使用注意事项。一、预载的原理首先,我们来了解一下图片预载的原理。传统的图片加载方式是等到图片全部下载完成才显示

vue报错找不到图片怎么办vue报错找不到图片怎么办Nov 19, 2022 pm 05:01 PM

vue报错找不到图片的解决办法:1、修改配置文件,将绝对路径改为相对路径;2、将图片作为模块加载进去,并将图片放到static目录下;3、将imageUrls引入响应的vue文件中,解析引用即可。

php5如何改80端口php5如何改80端口Jul 24, 2023 pm 04:57 PM

php5改80端口的方法:1、编辑Apache服务器的配置文件中的端口号;2、辑PHP的配置文件以确保PHP在新端口上工作;3、重启Apache服务器,PHP应用程序将开始在新的端口上运行。

如何在uniapp中实现图片滤镜效果如何在uniapp中实现图片滤镜效果Jul 04, 2023 am 11:05 AM

如何在uniapp中实现图片滤镜效果在移动应用开发中,图片滤镜效果是一种常见且受用户喜爱的功能之一。而在uniapp中,实现图片滤镜效果也并不复杂。本文将为大家介绍如何通过uniapp实现图片滤镜效果,并附上相关代码示例。导入图片首先,我们需要在uniapp项目中导入一张图片,以供后续滤镜效果的处理。可以在项目的资源文件夹中放置一张命名为“filter.jp

php写图片不显示不出来怎么办php写图片不显示不出来怎么办Nov 14, 2022 am 10:17 AM

php写图片不显示不出来的解决办法:1、找到并打开php.ini文件;2、找到“extension=php_gd2.dll”,并将前面的分号去掉;3、重新启动服务器;4、在绘图前清一下缓存即可。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),