-3

Hi every one could you please check my code in php. i have problem when i need to update my database record that including with picture, everytime i need to update i need to brow the picture again to update, if not it will overwrite the old picture and blank, So I want it optional for the picture when we update, if we no need update picture i want it still store the old image.

here is my code:

if(isset($_POST["save"])){
$sid = $_POST['sid'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$sex = $_POST['sex'];
$nationality = $_POST['nationality'];
$photo = $_FILES['photo']['tmp_name'];
$dept = $_POST['dept'];
$position = $_POST['position'];
$date = $_POST['date'];
$status = $_POST['status'];
$efile = $_POST['efile'];

if(!isset($photo))
  echo "Please select the photo";
  else
  {
  $photo=addslashes(file_get_contents($_FILES['photo']['tmp_name']));
  $photo_name = addslashes($_FILES['photo']['name']);
  $photo_size = getimagesize($_FILES['photo']['tmp_name']);
  if ($photo_size==FALSE)
  echo "that's not an image.";
 }

 $updateSQL = "UPDATE staff SET sid='$sid', fname='$fname', lname='$lname', sex='$sex', nationality='$nationality', photo='$photo', dept='$dept', position='$position', date='$date', status='$status', efile='$efile' WHERE sid='$_POST[hidden]'";
4

1 に答える 1

1

質問者様の分かる範囲で、

新しいイメージだけでなく、古いイメージも保持する必要があります。では、イメージ名のプレフィックスとして一意の番号を追加してみませんか。一意の ID を生成する関数uniqidを使用します。

元 :

$file_name = uniqid().$_FILES['photo']['tmp_name'];

次に、$file_name をデータベースに保存し、画像にアップロードします。

また、コードは SQL インジェクションに対して脆弱であることにも注意してください。

于 2013-04-28T04:35:18.867 に答える