Rumah > pembangunan bahagian belakang > tutorial php > 可牛看图web开放平台-PHP表单上传代码分享

可牛看图web开放平台-PHP表单上传代码分享

WBOY
Lepaskan: 2016-06-20 12:58:57
asal
1003 orang telah melayarinya

首先打开zendstudio编辑器:直接上代码:

?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 is bigger than this PHP installation allows'; break; case 2 : $error_log = 'The file is bigger than this form allows'; break; case 3 : $error_log = 'Only part of the file was uploaded'; break; case 4 : $error_log = 'No file was 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'; break; case 'image/png' : $extension = 'png'; break; case 'image/gif' : $extension = 'gif'; break; } } if (!is_file($img_data)) { die ('Image upload error!'); } // 图片保存路径,默认保存在该代码所在目录(可根据实际需求修改保存路径) $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 ();

备注:可牛看图提供两个上传接口供测试
一个是octet-stream方式上传,地址为:http://imgkaka.meitu.com/xiuxiu_web_pic_save.php
另一个是multipart/form-data方式上传,地址为:http://web.upload.meitu.com/image_upload.php
表单名称为"upload_file”。

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan