php上载文件只能保存一小部分

<html>
<head>
  <title>Uploading...</title>
</head>
<body>
<h1>Uploading file...</h1>

 

<?php
    echo '<pre>';
    print_r($_FILES);
    echo '</pre>';
    if ($_FILES['userfile']['error'] > 0)
        {
          echo 'Prolem: ';
          switch ($_FILES['userfile']['error'])
          {
            case 1: echo 'File exceeded upload_max_filesize'; break;
            case 2: echo 'File exceeded max_file_size'; break;
            case 3: echo 'File only partially uploaded'; break;
            case 4: echo 'No file uploaded'; break;
          }
          exit;
}


    if ($_FILES['userfile']['type'] != 'application/x-zip-compressed')

        {
           echo 'Problem: file is not pdf';
           exit;
       }

    $upfile = '/upload/'.$_FILES['userfile']['name'];

     if (is_uploaded_file($_FILES['userfile']['tmp_name']))
        {   
     if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
          {
           echo 'Problem: Could not move file to destination directory';
            exit;
            }
         }
    else
    {
        echo 'Problem: Possible file upload attack. Filename: ';
        echo $_FILES['userfile']['name'];
        exit;
     }

    echo 'File uploaded successfully<br><br>';

    $fp = fopen($upfile, 'r');
    $contents = fread($fp, filesize($upfile));
    fclose($fp);

    #$contents = strip_tags($contents);
    $fp = fopen($upfile, 'w');
    fwrite($fp, $contents);
    fclose($fp);

    echo 'Preview of uploaded file contents:<br><hr>';
    echo $contents;
     echo '<br><hr>';
?>
</body>
</html>

 

以上php上载文件脚本是在php & mysql 开发圣经的一段代码,在本机:PHP Version 5.2.6-1 运行时出现奇怪问题:上载之文

件在服务器上只有一部分得以保存, 经检查是这段代码 $contents = strip_tags($contents) 有问题,将它注解了就OK。

原因是因为   test

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值