สอบถามเกี่ยวกับวิธีเขียน upload file ไปยัง domain อื่นหน่อยครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามเกี่ยวกับวิธีเขียน upload file ไปยัง domain อื่นหน่อยครับ
สอบถามเกี่ยวกับวิธีเขียน upload file ไปยัง domain อื่นหน่อยครับ
ผมต้องต้องการจะอัพโหลดไฟล์รูปภาพจาก domain หลัก ไปเก็บไว้ที่ domain สำรองอีกที่นึง ต้องปรับเเก้ไข code อย่างไรครับ domain อยู่กันคนละ server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | if ( empty ( $_FILES [ 'image' ][ 'name' ]) || !isset( $_FILES [ 'image' ][ 'error' ])) { $_FILES [ 'image' ][ 'error' ] = 4; } if ( $_POST && $_FILES ) { $phpFileUploadErrors = array ( 0 => 'There is no error, the file uploaded with success' , 1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini' , 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form' , 3 => 'The uploaded file was only partially uploaded' , 4 => 'No file was uploaded' , 6 => 'Missing a temporary folder' , 7 => 'Failed to write file to disk.' , 8 => 'A PHP extension stopped the file upload.' , ); $uploadFolder = __DIR__ . DIRECTORY_SEPARATOR . 'uploaded' ; $allowedMimeTypes = [ 'image/jpeg' , 'image/png' , 'image/gif' ]; if (isset( $_FILES [ 'image' ][ 'error' ]) && $_FILES [ 'image' ][ 'error' ] !== UPLOAD_ERR_OK) { $output [ 'error' ] = true; $output [ 'message' ] = $phpFileUploadErrors [ $_FILES [ 'image' ][ 'error' ]]; } else { if (! is_dir ( $uploadFolder )) { $oldumask = umask(0); mkdir ( $uploadFolder , 0777); umask( $oldumask ); unset( $oldumask ); } $moveToFileName = $uploadFolder . DIRECTORY_SEPARATOR . $_FILES [ 'image' ][ 'name' ]; if (move_uploaded_file( $_FILES [ 'image' ][ 'tmp_name' ], $moveToFileName )) { $Finfo = new finfo(); $output [ 'uploadedMimeType' ] = $Finfo ->file( $moveToFileName , FILEINFO_MIME_TYPE); unset( $Finfo ); if (in_array( strtolower ( $output [ 'uploadedMimeType' ]), $allowedMimeTypes )) { http_response_code(201); $output [ 'uploadSuccess' ] = true; $output [ 'message' ] = 'Uploaded completed.' ; } else { http_response_code(400); $output [ 'uploadSuccess' ] = false; $output [ 'error' ] = true; $output [ 'message' ] = 'You have uploaded disallowed file types.' ; @unlink( $moveToFileName ); } } else { $output [ 'error' ] = true; $output [ 'message' ] = 'Unable to move uploaded file.' ; } unset( $moveToFileName ); } unset( $uploadFolder ); |

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
ดูเนื้อหานี้เป็นแนวทาง
บทความแนะนำที่เกี่ยวข้อง | |
---|---|
ประยุกต์ สร้าง FTP Function สำหรับการจัดการไฟล์ผ่าน FTP Protocal | อ่าน 10,599 |

ขอบคุณทุกการสนับสนุน
![]()