我在實習中做的練習涉及一個上傳頁面,一個表格頁面,它將輸出數據庫表的記錄和一個數據庫表。問題是,經過巨大的努力使所有連接良好,我遇到了一些麻煩,因為 index.php 頁面應該發送信息并且正在發送數組并保存數組而不是文件。下面是 index.php 頁面的 PHP 代碼: <?phpif (!isset($_POST['Enviar'])): // This if will search if the $_POST variable already has anything or not.$allowed = array('txt'); //This array contains the file types which are allowed.$uploadtime = time();$uploadfile = $_FILES['file_to_upload'];include 'db_connection.php';$sql="select * from uploads";$result = $conn->query($sql);$target_dir = "uploads/"; //variable that will save the name of the folder or way where the file will be saved.$target_file = $target_dir . basename($_FILES['file_to_upload']['name']); //NOTICE undefined index: file_to_upload... because it doesn't have any value safe there yet.$goon = 1; //This variable is used to check if there is any error messages or if the program can go on.$ext = pathinfo( $_FILES["file_to_upload"]["name"], PATHINFO_EXTENSION); // This will use the OS to get the file extension.if(!in_array($ext,$allowed) ) {echo 'Erro: Ficheiro n?o permitido. <br> Por favor, verifique se o formato do ficheiro é txt.';$goon = 0;} 第二段代碼中的字段名稱是數據庫中的名稱。誰能告訴我在 index.php 頁面中收到此錯誤消息有什么問題:注意:第 66 行 C:\xampp\htdocs\16082019\index.php 中的數組到字符串轉換
2 回答

撒科打諢
TA貢獻1934條經驗 獲得超2個贊
1st:謝謝你試圖幫助我xD。
第二:我已經有了一個適合我的練習的解決方案:
$uploadfile = $_FILES['file_to_upload'];
$uploadfile2 = $uploadfile['name'];
然后用舊線代替:
VALUES('".$_POST['file_name']."','$uploadfile2','$ext','$uploadtime')";

ABOUTYOU
TA貢獻1812條經驗 獲得超5個贊
“注意:數組到字符串的轉換”表示您正在嘗試將數組用作字符串。這是因為您將數組$_POST['file_name']與您的 INPUT 查詢字符串連接起來。您可以使用implode()函數將數組轉換為字符串:
$values = implode(',', $_POST['file_name']);
$sql = "INSERT INTO uploads (name,file_name,file_extension,uploaded_time)
VALUES('" . $values . "','$uploadfile','$ext','$uploadtime')";
- 2 回答
- 0 關注
- 169 瀏覽
添加回答
舉報
0/150
提交
取消