我試圖使用PHP將它們保存爲二進制形式到我的MySQL數據庫將文件上傳到我的服務器,但我不能讓它的工作,這裏是我使用的腳本,我相信它有什麼做「$ _FILES」,因爲我藉此出來的時候「& & $ _FILES [‘userfile的’] [‘大小’]> 0」的劇本開始運行,但隨後即用「$ _FILES」下的變量不是定義。PHP文件上傳
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) {
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
db_connect();
db_select();
$query = "INSERT INTO upload (name, size, type, content) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
db_disconnect();
echo "<br>File $fileName uploaded<br>";
}
將很方便檢查var_dump($ _ FILES)的輸出以準確查看內容。 – rojoca 2009-02-23 21:34:29