Detailed explanation of PHP avatar upload preview example

墨辰丷
Release: 2023-03-27 16:06:02
Original
1528 people have browsed it

This article mainly introduces the detailed explanation of PHP avatar upload preview examples. Interested friends can refer to it. I hope it will be helpful to everyone.

Speaking of uploading pictures, everyone is familiar with it. However, in future projects, you may not be allowed to upload pictures using the submit refresh page method. For example, uploading avatars, according to common sense, must be in the photo album. After selecting the photo, confirm the upload, and it will definitely not be uploaded through the form, click submit to refresh the upload. I will introduce to you two types of asynchronous non-refresh uploading of pictures. Picture preview: The first one is uploaded through the ready-made uploadfy plug-in. There are many examples on the Internet.

But what I will focus on introducing to you is the second method, uploading images through Ajax. Because using the uploadfy plug-in requires the device to support Flash in swf format, the first method cannot be used for most mobile phones. First, let me tell you about the uploading principle: control the file text field through js. After selecting the photo, submit the form asynchronously through Ajax, then use the position of the picture as the return value, and use js to set the src attribute of the img as the return value. .

Upload avatar area:

Code:


    无标题文档     

Copy after login


Upload processing page:


alert('该文件已存在!');"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],$filename); unlink($_POST["tp"]); echo ""; } } }
Copy after login


Principle:

Temporarily place the file in the form through the enctype="multipart/form-data" attribute In the tmp directory in the wamp folder, the file is saved in the system through the background php program.

The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

PHPjQuery Ajax Mysql How to implement the mood expression function_javascript skills

js imitates strtotime() and date() function implementation method in php_javascript skills

Use JavaScript to implementPHPurlencode and urldecode function_javascript skills


The above is the detailed content of Detailed explanation of PHP avatar upload preview example. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!