dongnei3634 2018-04-19 11:52
浏览 50
已采纳

在文件上传中找不到对象PHP [关闭]

Im trying to upload a file but i keep getting the sent to an object not found page error 404.

Im guessing that it is due to my path directory being wrong and the error exist between 'localhost' and C:\xampp\htdocs\PHP

Thanks in advance

My PHP code

<?php

$target_dir = "..\upload";
$target_file = $target_dir.basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$uploadError = "Error";
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);

    if(isset($_POST["submit"])) {
    $uploadOk = 1;
  }


    if (file_exists($target_file)) {
    $uploadOk = 0;
    $uploadError = "Sorry, file already exists.";}

    if ($_FILES["fileToUpload"]["size"] > 100000) {
    $uploadOk = 0;
    $uploadError = "Sorry, your file is too large.";}

    if($fileType != "txt" ) {
        $uploadOk = 0;
        $uploadError = "Sorry, only NOW TXT files are allowed.";}

    if ($uploadOk == 0) {
        echo $uploadError;} 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.";
}}?>

My HTML

<form action=".php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Submit" name="submit"> </form>

  • 写回答

1条回答 默认 最新

  • donglou1866 2018-04-19 11:54
    关注

    Change this :

    action=".php"

    To :

    action=""

    (To redirect to your current page by default)

    404 means the page where you redirected wasn't found after submitting the form. The value ".php" isn't good.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿