$ _GET上传图片

时间:2018-07-23 03:22:32

标签: javascript php

如果我使用$ _SESSION,我的代码可以工作,但是我需要使用URL中的文件名来命名。 这是示例URL:localhost / boldr / updateimage.php?EMPLOYEE_ID = 180627-027 我想重命名上载的图片,例如profile180627-027,但是在$ _GET中不起作用。

<?php

$id = $_GET['EMPLOYEE_ID'];


if (isset($_POST['submit'])){

$file = $_FILES['file'];

$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];

$fileExt = explode('.',$fileName);
$fileActualExt = strtolower(end($fileExt));

$allowed = array('jpg', 'jpeg', 'png');


if(in_array($fileActualExt, $allowed)){
  if($fileError == 0){
    if($fileSize < 1000000){
      $fileNameNew = "profile".$id.".".$fileActualExt;
      $fileDestination = 'img/'.$fileNameNew;
      move_uploaded_file($fileTmpName, $fileDestination);

      $sql = "UPDATE employees SET image=0 WHERE EMPLOYEE_ID='$id'";
      $result = mysqli_query($conn, $sql);
      header("Location: updateimage.php?EMPLOYEE_ID=$id");
    }else{
      echo "Your file is to big";
  }
}else{
  echo  "There was an error!";
}
}else{
  echo "You cannot upload files of this file";
}
}

 echo "<form action='updateimage.php' method='POST' enctype='multipart/form- 
 data'>
 <input type='file' name='file'>
 <button type='submit' name='submit'>Upload</button>
 </form>";

 ?>

1 个答案:

答案 0 :(得分:0)

在您的表单部分尝试如何操作: action ='updateimage.php?EMPLOYEE_ID = $ id'

相关问题