Bullish View Web open platform---php form upload code sharing

Source: Internet
Author: User
Tags php form

First open the Zendstudio Editor: directly on the code:

? 1234567891011121314151617181920212223 0) {$filename = $save _path. ‘/‘ . Uniqid (). '. jpg '; $handle = fopen ($filename, ' w+ '); Fwrite ($handle, $postdata); Fclose ($handle); if (Is_file ($filename)) {echo ' image data save Successed,file: '. $filename; exit ();} else {die (' image upload error! ' ); }} else {die (' Image data not detected! ');}

? 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 0) {switch ($FILES [' Filedata '] [' ERROR ']) {Case 1: $error _log = ' The file was bigger than this PHP installation allows '; "Case 2: $error _log = ' The file is Bigger than this form allows '; Break Case 3: $error _log = ' Only part of the file is uploaded '; Break Case 4: $error _log = ' No file ' is uploaded '; Break Default:break; } die (' Upload error: '. $error _log); } else {$img _data = $files[' Filedata ' [' tmp_name ']; $size = getimagesize ($img _data); $file _type = $size [' MIME ']; if (!in_array ($file _type, Array (' image/jpg ', ' image/jpeg ', ' image/pjpeg ', ' image/png ', ' image/gif '))) {$error _log = ' Only allow Jpg,png,gif '; Die (' Upload error: '. $error _log); } switch ($file _type) {case ' image/jpg ': Case ' image/jpeg ': Case ' image/pjpeg ': $extension = ' jpg '; /png ': $extension = ' png '; Break Case ' image/gif ': $extension = ' gif '; Break }} if (!is_file ($img _data)) {die (' image upload error! ');}//Picture save path, default saved in the directory where the code is located (can modify save path according to actual needs) $save _path = DirName (FILE); $uinqid = Uniqid (); $filename = $save _path. ‘/‘ . $uinqid. ‘.‘ . $extension; $result = Move_uploaded_file ($img _data, $filename); if (! $result | |!is_file ($filename)) {die (' image upload error! ');} echo ' Image data save Successed,file: '. $filename; Exit ();

Note: The bull view provides two upload interfaces for testing
One is the octet-stream way to upload, the address is: http://imgkaka.meitu.com/xiuxiu_web_pic_save.php
The other is multipart/form-data way to upload, the address is: http://web.upload.meitu.com/image_upload.php
Table sole name is called "Upload_file".

Bullish View Web open platform---php form upload code sharing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.