URL中的PHP发布而不使用GET

马克斯·博盖特(Max Bogatec)

我目前正在编写一些代码。您应该能够上载文件并选择文件类型的位置。

我正在使用url在上传页面上进行数据库输入,因此我的链接应类似于

www.mydomain.domain?id=1&type=type

但是php仅获取ID,因为它使用了上一页中的get。

所以看起来像这样

www.mydomain.domain?id=1&type=

所以我的问题是如何在URL中获得选择?

我尝试用jQuery,但我很烂; D。

我的表格代码:

<?php
$datetype = $_POST['dateiart'];
echo $datetype;
$ek = $_GET['id'];
?>

<form action="upload.php?id=<?php echo $ek; ?>&type=<?php echo $datetype;?>"  target="_blank" method="post" enctype="multipart/form-data" id="dateiauswahl">
    Datei zum hochladen auswählen
    <input type="file" name="fileToUpload" id="fileToUpload"> <br>
    <input onclick="myFunction()" type="submit" value="Datei hochladen" name="submit"><br><br>

<input type="hidden" value="<?php echo $ek?>" id="id" name="submit"><br><br>

      <label>Dateiart:
    <select  name="dateiart" form="dateiauswahl" size="5">
      <option value="EK-Rechnung">EK-Rechnung</option>
      <option value="Kaufvertrag">Kaufvertrag</option>
      <option value="VK-Rechnung">VK-Rechnung</option>
      <option value="Datenblatt">Datenblatt</option>
      <option value="Sonstige">Sonstige</option>
    </select>
  </label>
    </div>
</form>

upload.php

<?php
$pdo = new PDO('mysql:host=localhost;dbname=', '', '');
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$ek = $_GET['id'];
$dateiart = $_GET['type'];
echo $dateiart;
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 50000000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "pdf"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }


        $statement = $pdo->prepare("INSERT INTO Dateien (Link, EKNR, Datei_Bezeichnung) VALUES (:Link, :EKNR, :Datei_Bezeichnung)");
        $result = $statement->execute(array('Link' => $target_file, 'EKNR' => $ek, 'Datei_Bezeichnung' => $dateiart));

}
?>
克劳迪奥·金

将参数作为隐藏输入传递,而不是将其打印在表单的操作URL的查询字符串中。使用htmlspecialchars功能来防止安全问题。

<?php 
 if (!isset($_GET['id']) || !isset($_GET['type'])){
     die('Missing parameters');
 }
?>


<form action="upload.php"  target="_blank" method="post" enctype="multipart/form-data" id="dateiauswahl">
    Datei zum hochladen auswählen

    <input type="hidden" name="id" value="<?php echo htmlspecialchars($_GET['id']) ?>">
    <input type="hidden" name="type" value="<?php echo htmlspecialchars($_GET['type']) ?>">


    ....... other inputs

</form>

upload.php脚本中的从超级$_POST全局获取它们

$ek = $_POST['id'];
$dateiart = $_POST['type'];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Dompdf不使用已发布的php表格打印表格

检查swf url是否可用,或者不使用php get_headers Content-Type

如何使用PHP在url中发布值

在URL中传递数组,而不使用PHP的列表的最小值

使用.htaccess使用和不使用.php的特定URL

仅使用Cordova应用程序中的URL将图像发布到PHP

如何不使用file_get_contents读取PHP中的JSON文件?

如何在不使用表单的情况下从Rails应用程序发布到外部URL

Python selenium chrome 不使用 driver.get(url) 下载

Django不使用get_absolute_url方法

Sinon 不使用参数模拟为 GET 提供的 URL

PHP使用$ _GET而不在URL中定义变量?

在发布请求后访问 URL 中的旧 get 参数

使用PHP发送/发布表单数据到Url

不使用已发布的 MassTransit 子类

PHP中的GET URL参数

不使用标头重定向中的 url

MsBuild发布网站而不使用发布配置文件

如何在不使用post和get方法的情况下将php文件执行到jquery中?

如何使用file_get_contents在PHP中发布数据?

在MVC 5中使用相对URL进行AJAX发布

如果在 PHP 中不使用空变量/数据

在HTML中调用PHP文件而不使用输入标签

php pdo bindbinam中的数组参数不使用foreach循环

不使用密码保护Apache中的php

Apache .htaccess-使用“ .php”阻止所有URL,但不使用“ index.php”阻止

我需要将哪些PHP插入此mysqli_fetch_array中,以确保不使用NULL url?(html + php + mysql网站问题)

不使用方案验证URL

在jQuery中不使用