1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

求修改一个PHP上传代码

本帖由 lane2005-11-09 发布。版面名称:后端开发

  1. lane

    lane New Member

    注册:
    2005-09-05
    帖子:
    6,548
    赞:
    29
    代码:
    <? 
    \$fname = \$_FILES['MyFile']['name'];   
    \$do = copy(\$_FILES['MyFile']['tmp_name'],\$fname); 
    if (\$do) 
    { 
        echo"上传成功<p>"; 
        echo "http://".\$SERVER_NAME."".dirname(\$PHP_SELF)."/".\$fname.""; 
    } else { 
        echo "上传失败"; 
    } 
    ?> 
    <form ENCTYPE="multipart/form-data" ACTION="<?php echo"".\$PHP_SELF.""; ?>" METHOD="POST"> 
    <input NAME="MyFile" TYPE="file"> 
    <input VALUE="提交" TYPE="submit"> 
    </from>
    
    偶不会PHP,保存运行后,页面是下面这样的,但是可以正常上传东西,我怎么修改呢?

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 2

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 2

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 3

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 3

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 3

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 4

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 7

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 7

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 7

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/ftp/512j.com/f/l/d/fld/upload.php on line 12
    锘?br /> Warning: copy(): Unable to access in /home/ftp/512j.com/f/l/d/fld/upload.php on line 3
    涓婁紶澶辫触
     
  2. lane

    lane New Member

    注册:
    2005-09-05
    帖子:
    6,548
    赞:
    29
    我把所有的'\' 都去掉,出了这个
    Warning: copy(): Unable to access in /home/ftp/512j.com/f/l/d/fld/upload.php on line 3
    上传失败
     
  3. fyfei

    fyfei New Member

    注册:
    2005-10-07
    帖子:
    9,067
    赞:
    46
    帮你
    我也想要一个上传的文件。
     
  4. lane

    lane New Member

    注册:
    2005-09-05
    帖子:
    6,548
    赞:
    29
    我自己搞定一个,不过路径不太完美,代码给你吧~

    代码:
    <html>
    <head>
    <title>图片上传页面</title>
    <style type="text/css">
    <!--
    body,td,th {
    	font-size: 12px;
    	color: #000000;
    }
    body {
    	background-color: #CCCCCC;
    }
    .style1 {
    	font-size: 14px;
    	color: #000000;
    	font-weight: bold;
    }
    .style2 {color: #FF0000}
    -->
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
    <body>
    <div align="center">
    <?
    if(isset($_FILES['newpic']))
    {
    $pt=split('/',$_FILES['newpic']['type']);
    if($pt[0]!='image'){
    echo"<script>alert('对不起,只能上传图片文件'); </script>";
    }else{
    $img_dir="photos/"; 
    $copy=copy($_FILES['newpic']['tmp_name'],"$img_dir".$_FILES['newpic']['name']);
    if($copy==1){
    echo "添加成功!";
    echo "贴图代码 http://".$SERVER_NAME."/".$img_dir."/".$_FILES['newpic']['name']."[[COLOR="Red"]#[/COLOR]img]"; 
    }else{
    echo "图片copy失败";
    }
    }
    }
    ?>
    <table width="350" height="88" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#666666" bgcolor="#efebef" >
    <tr align="center"> 
    <td height="25" colspan="2"><span class="style1">图片添加程序</span></td>
    </tr>
    <tr align="center"> 
    <td height="25" colspan="2"><span class="style2">图片上传成功后请将给出的代码复制到文章编辑框适当位置</span></td>
    </tr>
    <tr> 
    <td width="55" height="35" align="center">选择图片上传→</td>
    <td width="288" align="center" valign="middle">
    <form action="<? echo $PHP_SELF;?>" method="post" enctype="multipart/form-data" name="form">
      <div align="center">
      <input name="newpic" type="file" id="newpic">
      <br><br>
      <input type="submit" name="Submit" value="上传图片">&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="Submit2" value="重置">
      </div>
    </form></td>
    </tr>
    </table>
    </div>
    </body>
    </html>[/CODE]
    
    红色的#是/