0
存儲的個人資料相片所以,我目前所面對的這個代碼,但它只能存儲PIC的文件夾中,並沒有超越這一步。 表單中輸入的數據不會被存儲在數據庫.... :(與分佈數據
<?php
$sub=0;
ini_set("display_errors", 0);
if(isset($_REQUEST['submited'])) {
// your save code goes here
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2097152)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "";
if (file_exists("media/" . $_FILES["file"]["name"]))
{
echo "<font size='4' color='red'><b>We are sorry, the file you trying to upload already exists.</b></font>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"media/" . $_FILES["file"]["name"]);
$sub= 1;
$mysqli = new mysqli("localhost", "root", "", "cms");
// TODO - Check that connection was successful.
$name = $_POST["name"];
$surname = $_POST["surname"];
$about = $_POST["about"];
$visible = $_POST["visible"];
$admin = $_POST["admin"];
$file_path = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$stmt = $mysqli->prepare("INSERT INTO schauspieler (
name, surname, about, visible, admin, date, file_path, photo_type, photo_size
) VALUES (
'$name', '$surname', '$about', $visible, $admin, '$file_path', '$type', '$size', CURRENT_TIMESTAMP,
)");
// TODO check that $stmt creation succeeded
// "s" means the database expects a string
$stmt->bind_param("s", $name, $surname, $about, $visible, $admin, $file_path, $type, $size);
$stmt->execute();
$stmt->close();
$mysqli->close();
echo "<font size='7' color='red'><b> Success! Your photo has been uploaded.</b></font>";
}
}
}
else
{
echo "<font size='4' color='red'><b>We are sorry, the file you trying to upload is not an image or it exceeds 2MB in size.</b></font><br><font color='blue'><i>Only images under size of 2MB are allowed</i></font>.";
}
}
?>
誰能告訴我,我錯過了什麼?
感謝名單傢伙
乾杯 克里斯
已經做到了,你告訴我,當然現在一切都更新非常漂亮。只有file_path和photo_type的列仍爲空。並且在大小列中總是有一個0.意味着文件根本不存儲。也許與VA有關? – Chris 2014-09-24 05:44:25
有一個問題,我的專欄和他們的安排。有一個我不再使用。現在這一切都像一個魅力。感謝名單 – Chris 2014-09-24 05:53:46
我很高興我可以幫助你。所以如果我回答你的問題,你能接受我的答案是「解決你的問題」嗎? – 2014-09-24 06:40:41