doutuoben6908 2015-08-31 14:45
浏览 33

PHP问题(文件上传)

I have been working on a website for some time now, and the code I used here worked about a month ago, then I tried putting the file in a subfolder, and redirecting the move_uploaded_file function, but it doesn't seem to be working. To be specific, both the:

if((!empty($_FILES["uploaded_letter"])) &&  ($_FILES['uploaded_letter']['error'] == 0)) 

and

if((!empty($_FILES["uploaded_list"])) && ($_FILES['uploaded_list']['error'] == 0))

statements are returning false. If anyone could please help with that, that would be awesome! Thanks!

<html>
    <head>
        <title>VAA Chapter 11</title>
        <!--favicon-->
        <link rel="shortcut icon" href="favicon.ico" />

        <!--global CSS-->
        <link href="vaa.css" rel="stylesheet" type="text/css">

        <!--local CSS-->
        <style type="text/css">

        </style>
    </head>
    <body>
        <?php
        function testPassword(){
            $password = $_POST['password'];
            if($password == 'You aint guessin this'){
                echo 'welcome!!! <br/>
                <form enctype="multipart/form-data" action="" method="post">
                        <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <br/>
                        add newsletter: <input name="uploaded_letter" type="file" /><br/><br/>
                        add list: <input name="uploaded_list" type="file" /><br/><br/>
                        <input type="submit" name="load" value="Upload" />
                </form>';
            }
            else{
                echo "you have no power here";
            }
         }
        function upload(){
            if((!empty($_FILES["uploaded_letter"])) &&  ($_FILES['uploaded_letter']['error'] == 0)) {
                $filename = basename($_FILES['uploaded_letter']['name']);
                $ext = substr($filename, strrpos($filename, '.') + 1);

                if (($ext == "pdf") && ($_FILES["uploaded_letter"]["size"] < 35000000)) {
                    $newname = dirname(__FILE__,1).'/newsletters/'.$filename;

                    move_uploaded_file($_FILES['uploaded_letter']['tmp_name'],$newname);
                } 
                else {
                    echo "Error: file is too large";
                }
            } 
            else {
                echo "Error: No file uploaded";
            }
            if((!empty($_FILES["uploaded_list"])) && ($_FILES['uploaded_list']['error'] == 0)) {
                $filename = basename($_FILES['uploaded_list']['name']);
                $ext = substr($filename, strrpos($filename, '.') + 1);

                if (($ext == "txt") && ($_FILES["uploaded_file"]["size"] < 35000)) {
                    $newname = dirname(__FILE__,1).'/'.$filename;

                    move_uploaded_file($_FILES['uploaded_list']['tmp_name'],$newname);
                } 
                else {
                    echo "Error: file is too large";
                }
            } 
            else {
                echo "Error: No file uploaded";
            }
        }
        function testUpload(){
            if(isset($_POST['load'])){
                upload();
            }
        }
        ?>    
        <form method="post">
            <input type="text" name="password" />
            <input type="submit" value="OK" />  
        </form>
        <?php testPassword(); testUpload(); ?>
    </body>
</html>
  • 写回答

3条回答 默认 最新

  • dongying9756 2015-08-31 15:11
    关注

    it is better if you have more than one file to upload to use array for naming your file foe example add newsletter: <input name="uploaded_letter[]" type="file" /> add list: <input name="uploaded_letter[]" type="file" />then you can use foreach in target page

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看