Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upload pictures by Ajax

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "Ajax how to upload pictures", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to upload pictures in Ajax" this article.

1. Upload the picture to the server.

two。 The background will send the picture address to the html page and show it in the form of a picture.

3. Add the picture address to the input form the day after tomorrow, and the form is hidden.

4. The front end deletes the picture, and removes the picture and form data through the js operation.

5. The picture upload form is separate. Cannot be nested in the overall form.

6. Great picture upload, you can deal with the picture. Compress, add watermark, etc.

7. Click btn, trigger the picture click, after the picture changes, trigger the picture form submission.

Click the button

The picture outside the station is uploaded. (2)] add a picture

Upload form

Trigger event

("# up_btn") .click (function () {$("# carousel-photoimg"). Click ();}); $('# carousel-photoimg'). On ('change', function () {var status = $("# up_status"); var btn = $("# up_btn"); $("# imageform") .ajaxForm ({target:' # carousel-preview', beforeSubmit:function () {/ / display status.show () with the loaded picture before submission After btn.hide ();}, success:function () {/ / submit, the loaded image shows status.hide (); btn.show ();}, error:function () {status.hide (); btn.show ();}}) .submit ();})

Back-end verification and processing

Function carouselUpload () {$path = "Uploads/Store/goods/" .date ("Ymd"). /'; if (! file_exists ($path)) {mkdir ($path, 0777, true);} $extArr = array ("jpg", "png", "gif", "jpeg"); if (isset ($_ POST) and $_ SERVER ['REQUEST_METHOD'] = "POST") {$name = $_ FILES [' photoimg'] ['name']; $size = $FILES [' photoimg'] ['size'] If (empty ($name)) {echo 'Please select a picture to upload'; exit;} $ext = $this- > extend ($name); if (! in_array ($ext,$extArr)) {echo 'picture format error!' ; exit;} if ($size > (2000mm 1024)) {echo 'picture size cannot exceed 2m rand exit;} $image_name = time (). Rand (100999). ". $ext;$tmp = $_ FILES [' photoimg'] ['tmp_name']; if (move_uploaded_file ($tmp, $path.$image_name)) {echo'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report