Simple PHP upload image, delete image implementation code
Upload image:
Copy code The code is as follows:
if (!empty($_FILES["img"]["name"])) { //Extract the file domain content name and determine
$path =”uppic/”; //Upload path
if(!file_exists($path))
{
//Check whether the folder exists, if not, create it and give the highest permissions
mkdir(“$path”, 0700 );
}//END IF
//File formats allowed to be uploaded
$tp = array("image/gif","image/pjpeg","image/jpeg");
//Check whether the uploaded file is allowed Upload type
if(!in_array($_FILES["img"]["type"],$tp))
{
echo “<script>alert('wrong format');history.go(-1) ;</script>”;
exit;
}//END IF
$filetype = $_FILES['img']['type'];
if($filetype == 'image/jpeg'){
$ type = '.jpg';
}
if ($filetype == 'image/jpg') {
$type = '.jpg';
}
if ($filetype == 'image/pjpeg') {
$ type = '.jpg';
}
if($filetype == 'image/gif'){
$type = '.gif';
}
if($_FILES["img"]["name"])
{
$today=date(“YmdHis”); //Get the time and assign it to the variable
$file2 = $path.$today.$type; //The full path of the image
$img = $today.$type; //Picture name
$flag=1;
}//END IF
if($flag) $result=move_uploaded_file($_FILES["img"]["tmp_name"],$file2);
//Pay special attention here The first parameter passed to move_uploaded_file is the temporary file uploaded to the server
}//END IF
//Then write the value of $img to the corresponding field in the database
Delete the image:
Copy the code The code is as follows:
unlink(“uppic/”.$img); //Of course, the value of the variable is read from the database. PHP is much simpler to delete pictures than ASP
The above has introduced the simple PHP code to upload pictures and delete pictures, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Methods to open img files include using virtual optical drive software, using compression software, and using special tools. Detailed introduction: 1. Use virtual optical drive software to open, download and install a virtual optical drive software, right-click the img file, select "Open with" or "Associated Program", select the installed virtual optical drive software in the pop-up dialog box, virtual The optical drive software will automatically load the img file and use it as a disc image in the virtual optical drive. Double-click the disc icon in the virtual optical drive to open the img file and access its contents, etc.

In C language, if statement is usually used to execute a specific block of code based on a single condition. However, multiple conditions can be combined to make a determination using logical operators such as &&, ||, and !. Including using logical AND (&&) to judge multiple conditions, using logical OR (||) to judge at least one condition, using logical NOT (!) to judge the negation of a single condition, as well as nesting if statements and using parentheses to clarify priority.

How to open the img file: 1. Confirm the img file path; 2. Use the img file opener; 3. Select the opening method; 4. View the picture; 5. Save the picture. The img file is a commonly used image file format, usually used to store picture data.

img is a file compression format, mainly used to create image files of floppy disks. It can be used to compress the contents of an entire floppy disk or an entire CD; files with the extension ".IMG" are created using this file format. ; The img file includes 3 basic nodes, namely "Ehfa_HeaderTag", "Ehfa_File" and "Ehfa_Entry".

An error occurs when ubuntu mounts a mobile hard disk: mount: unknownfilesystemtype'exfat'. The processing method is as follows: Ubuntu13.10 or install exfat-fuse: sudoapt-getinstallexfat-fuseUbuntu13.04 or below sudoapt-add-repositoryppa:relan/exfatsudoapt-getupdatesudoapt-getinstallfuse- exfatCentOS Linux mount exfat format USB disk error solution to load extfa in CentOS

The usage of the Type keyword in Go includes defining new type aliases or creating new structure types. Detailed introduction: 1. Type alias. Use the "type" keyword to create an alias for an existing type. This alias does not create a new type, but only provides a new name for the existing type. Type aliases can improve code. The readability of the code makes the code clearer; 2. Structure type. Use the "type" keyword to create a new structure type. The structure is a composite type that can be used to define custom types containing multiple fields. etc.

This article will introduce seven ways to get high-quality output using the free BingImageCreator. BingImageCreator (now known as ImageCreator for Microsoft Designer) is one of the great online artificial intelligence art generators. It generates highly realistic visual effects based on user prompts. The more specific, clear, and creative your prompts are, the better the results will be. BingImageCreator has made significant progress in creating high-quality images. It now uses Dall-E3 training mode, showing a higher level of detail and realism. However, its ability to consistently produce HD results depends on several factors, including fast

How to delete images on Xiaomi mobile phones? You can delete images on Xiaomi mobile phones, but most users don’t know how to delete images. Next is the tutorial on how to delete images on Xiaomi mobile phones brought by the editor. Interested users can come and join us. Let's see! How to delete images on Xiaomi mobile phone 1. First open the [Album] function in Xiaomi mobile phone; 2. Then check the unnecessary pictures and click the [Delete] button in the lower right corner; 3. Then click [Album] at the top to enter the special area , select [Recycle Bin]; 4. Then directly click [Empty Recycle Bin] as shown in the figure below; 5. Finally, directly click [Permanent Delete] to complete.
