我使用此代碼替換圖像,但圖像未上載到上載文件夾中,但數據庫已更新。我需要更換圖像。如何在php中替換圖片?
<?php
require("header.php");
$patientid = $_POST['patientid'];
$pname = $_POST['pname'];
$fname = $_POST['fname'];
$address = $_POST['address'];
if(!$pname || !$address) {
echo "<center>";
echo "Fillup required fields<br><br>";
echo "</center>";
}
else {
$ran2 = $patientid;
$new_name2 = $ran2."b";
$new_file_name2 = $new_name2."."."jpg";
$path = "./members/".$new_file_name2;
$copied = move_uploaded_file($_FILES['img_name']['tmp_name'], $path);
if ($copied) {
$sql = mysql_query("UPDATE info_store
SET pname='$pname', fname='$fname', address='$address', image1='$new_file_name2'
WHERE patientid='$patientid'");
return true;
}
else {
echo "<center><h3>There are An Errors In Uploading!</h3></center>";
return false;
}
}
?>
請給我一個解決方案。
一些問題:無法檢查上傳是否成功。 SQL注入漏洞。假設數據庫查詢成功。無意義的字符串連接操作。可怕的表單驗證... Ouch。 – 2011-12-27 17:35:53
請檢查您的上傳文件大小限制 – 2011-12-27 17:49:35