dongnei3634 2018-04-19 03: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 03: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部