解决方案 »

  1.   

    怎么打开的? 出现notice是因为你没提交表单时,$_FILES 为空数组。你应该判断一下。
      

  2.   

    去掉<input type="hidden" name="MAX_FILE_SIZE" value="300000" /> 文件上传的大小限制试试MAX_FILE_SIZE本来就存在问题不建议使用,你这个限制是约300KB一下的文件才可以上传 我觉得你上传的文件应该超过这个大小了  
      

  3.   

    1.
    Notice: Undefined index: upfile in C:\Apache24\htdocs\05_PHP_FileUpload\fileupload.php on line 9
    <input type = "file" name = "upfile"/>  
    沒有獲取不到圖片。2.MAX_FILE_SIZE
    <input type="hidden" name="MAX_FILE_SIZE" value="300000" /> 可以改大一点。
    修改后如下:<html>
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>文件上传</title>
      </head>
      
      <body>
      <?php
        if(isset($_POST['send'])){
            $files = $_FILES['upfile'];
            print_r($files);
            if(is_uploaded_file($files['tmp_name'])){
                echo "nihao";
                $name = $files['name'];
                $tmp_name = $files['tmp_name'];
                $type = $files['type'];
                echo $name."<br/>".$tmp_name."<br/>".$type;
                if (move_uploaded_file($_FILES['upfile']['tmp_name'], "myup/".$name)) {
                    echo "File is valid, and was successfully uploaded.\n";
                } else {
                    echo "Possible file upload attack!\n";
                }
            }
        }
     ?> 
        <form action = "fileupload.php" enctype = "multipart/form-data" method="post">
            <input type="hidden" name="MAX_FILE_SIZE" value="10300000" />
            选择文件:<br/>
            <input type = "file" name = "upfile"/>  
            <input type="hidden" name="send" value="true">
            <input type = "submit" value="上传" />
        </form>
      </body>
    </html>
    Array ( [name] => 18.jpg [type] => image/jpeg [tmp_name] => G:\wamp\tmp\php1B9.tmp [error] => 0 [size] => 75349 ) nihao18.jpg
    G:\wamp\tmp\php1B9.tmp
    image/jpegFile is valid, and was successfully uploaded.上传成功。
      

  4.   

    把你的上传文件路径改一下
    "./myup/".$name
      

  5.   

    还有notice出现的原因很简单
    你在一个页面中放上传文件的表单和处理上传
    又没有加判断 很自然会出现notice
    如果你非要放一起
    就在整个PHP处理过程之前判断一下$_FILES是否为空
      

  6.   

    上傳後,比對一下圖片的size是否一致。
    如果是一致的。就表示上傳成功。你講不能顯示。例如圖片在myup/1.jpg
    那麼訪問 http://localhost/myup/1.jpg看看能不能顯示。
      

  7.   

    PHP上传图片功能
    <?php
    session_start();
    header('Content-Type:text/html;charset=gb2312');
    include_once 'conn/conn.php';
    //上传图片名称、类别、文件和图片描述
    $xuanxiang = $_POST['xuanxiang'];
    $url_name = $_POST['url_name'];
    $hao = $_POST['xuanxiang'];
    $file = $_FILES['tb_flash_pic'];
    $uptime=date("Y-m-d h:i:s");
    //上传图片的信息数组
    $fileinfo = getimagesize($file['tmp_name']);
    //判断上传文件大小
    if($file['size'] > (1024 * 20000)){
    echo "<script>alert('上传文件超过200K的上限!');history.go(-1);</script>";
    exit();
    }
      
    //生成新文件名
    $url = $url_name;
    $url_tet = fopen('../flash_data/urldizhi.txt','ab+');
    fwrite($url_tet,$url);
        fclose($url_tet); $newname = $xuanxiang.strrchr($file['name'],'.');
    //上传图片
    move_uploaded_file($file['tmp_name'],'../flash_data/'.$newname);
    move_uploaded_file($url_name['tmp_name'],'../flash_data/urldizhi.txt/');
    //生成缩略图
        //$query=mysql_query("update tb_forum_user set tb_forum_type='$_POST[tb_forum_type]' where tb_forum_id='$update_id'");
    //保存到数据库

    $sql = mysql_query("insert into tb_flash(hao,url_name,tb_flash_pic,uptime) values('$hao','$url_name ','$newname','$uptime')",$conn);
    if($sql==true){
    echo "<script>alert('上传图片成功!');window.location.href='index.php';</script>";
    }else{
       echo "<script language='javascript'>alert('对不起,上传失败!');history.back();</script>"; 
       exit;
    }
    ?>