0
我一直在努力爭取一段時間,讓這個單一按鈕上傳工作,我已經嘗試了幾種方法來提交上傳和這一個我似乎工作到了點,但後來的東西該PHP似乎不喜歡提交,沒有這個JS作爲一個常規的選擇文件和上傳,但我很快添加JS(似乎工作)PHP然後不起作用。按鈕上傳問題
我完全困惑,爲什麼發生這種情況!
任何意見讚賞謝謝!
上傳表單
<form name="form" method="POST" enctype="multipart/form-data" action="updateProfilePic_script.php">
<div class="update_header_pic">
<input type = 'button' value = 'Choose image'
onclick ="javascript:document.getElementById('Photo').click();">
<input id='Photo' type='file' style='visibility: hidden;' name='Photo' onchange='submit();'/>
</div>
</form>
的PHP
<?
session_start();
$user = $_SESSION['username'];
$hostname = "localhost";
$db_user = "xxxusername";
$db_password = "xxxpassword";
$database = "xxxdatabase";
$db_table = "user_profile_pic"; // image table
# THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$uploadDir = 'usermedia/users/images/profileimages/'. $user .'/';//Image Upload Folder
if (!is_dir($uploadDir) && !mkdir($uploadDir)){
die("Error creating folder $uploadDir");
}
if(isset($_POST['submit'])) {
$date = date("Y-m-d H:i:s");
$unique = substr(number_format(time() * rand(),0,'',''),0,10);
$fileName = $unique .'-'.$_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO $db_table (Image , username , datetime , filesize , filetype) VALUES ('$filePath' , '$user' , '$date' , '$fileSize' , '$fileType')";
mysql_query($query) or die('Error, query failed');
header('Location: edit_myProfile.php');
}
?>
您是否認爲像print_r($ _ FILES),print_r($ _ POST)n東西?任何其他錯誤? – 2013-03-17 17:35:59
您的表單中沒有名爲'submit'的元素,但您正在測試它if'isset($ _ POST ['submit'])){' – CBroe 2013-03-17 17:40:06