Nguồn code ở freetust ,em copy thử test mà nó bị lỗi gì đấy e k rõ .em thử thôi nhé
Thử thử thử ý
index.php
<html> <head> <title>File Upload Using PHP and cURL - freetuts.net</title> </head> <body> <form action="curl.php" method="post" enctype="multipart/form-data"> <table border="1"> <tr> <td>Upload</td> <td><input name="file" type="file" id="file"/></td> </tr> <tr> <td> </td> <td><input name="btnUpload" type="submit" value="Upload" /></td> </tr> </table> </form> </body> </html>
curl.php
<?php // Nếu submit form if (isset($_POST['btnUpload'])){ $filename = $_FILES['file']['name']; $filedata = $_FILES['file']['tmp_name']; $filesize = $_FILES['file']['size']; if ($filedata != ''){ $headers = array("Content-Type:multipart/form-data"); $postfields = array("filedata" => "@$filedata", "filename" => $filename); $ch = curl_init('http://*****/wap/upload.php'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); curl_setopt($ch, CURLOPT_INFILESIZE, $filesize); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); if(!curl_errno($ch)){ $info = curl_getinfo($ch); if ($info['http_code'] == 200){ echo 'Upload thành công'; } } else { echo curl_error($ch); } curl_close($ch); } else { echo 'Bạn chưa chọn file để upload'; } } ?>
upload.php
File này e thử edit hàm copy() thành move_uploaded_file()
<?php $uploadpath = "upload/"; $filedata = $_FILES['filedata']['tmp_name']; $filename = $_POST['filename']; if ($filedata != '' && $filename != ''){ copy($filedata,$uploadpath.$filename); move_uploaded_file($uploadpath, "$filedata/$filename"); } ?>
Giúp e với
En thử nhé ,thử ấy