想請各位前輩協助 謝謝~
以下是我在練習時遇到的問題:
目的: 於上傳頁面按下上傳的按鈕後,轉到下一頁組XML並將檔案上傳到伺服器上。
目前XML檔案已可正常下載至本機,但無法直接上傳到伺服器上
請問是使用move_uploaded_file函式將檔案上傳嗎?
有嘗試過用瀏覽檔案的方式進行上傳,可正常上傳
但是要試著改成按下上傳的按鈕後直接上傳,就會一直失敗
$_FILES['upload']['tmp_name'] 這邊不知道該怎麼處理
程式碼如下(我是以DW去寫的) 謝謝!
前台:
<a href="export.php?<?php echo $MM_keepNone.(($MM_keepNone!="")?"&":"")."dept=".urlencode($row_Recordset['dept']) ?>"><input style="CURSOR: hand" type="submit" value="通訊錄匯出" name="name" /></a>
後台:
<?php require_once('Connections/phonebook.php'); ?>
<?php
$colname_Recordset1 = "-1";
if (isset($_GET['dept'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['dept'] : addslashes($_GET['dept']);
}
mysql_select_db($database_phonebook, $phonebook);
$query_Recordset1 = sprintf("SELECT * FROM Phone WHERE dept = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $phonebook) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
header ('content-type: text/xml; charset=utf-8');
header('Content-Disposition: form-data; filename= '.$row_Recordset1['dept'].".xml");
?>
<?php do { ?>
<DirectoryEntry>
<Name><?php echo $row_Recordset1['name']; ?></Name>
<Telephone><?php echo $row_Recordset1['telephone']; ?></Telephone>
</DirectoryEntry>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<?php
mysql_free_result($Recordset1);
?>
<?php
$uploaddir = '/xml/';
$uploadfile = $uploaddir . basename($_FILES['upload']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['upload']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\\\\n";
} else {
echo "Possible file upload attack!\\\\n";
}
?>
這邊看不到任何你上傳檔案的動作存在。
正常來說最基本的也得要有 form 才對
你可以參考海綿的範例。
我就不在重覆
可以的話,多學一下。不要只會用dw拖拉。
你會搞不清楚方向。