不知道为什么,以下是代码
<html>
 <head>
 <title>上传图片</title>
 </head>
 <body>
 <form action="build.php" method="post" enctype="multipart/form-data" name="form1">
   <p>
     <label>
       <input type="file" name="img" id="img">
     </label>
   </p>
   <p>
     <label>
       <input type="submit" name="button" id="button" value="ok">
     </label>
   </p>
 </form>
</body>
</html>
<?php
$path = "studentimages";
$mode = 0777;
$netId = "G199026";
mkdir($path,$mode);$file_source = $_POST['img'];
if ( !copy( $file_source,$path."/".$netId.".jpg" ) )
 echo "fail";
 else
echo "successful"; //copy($filePath,$dest."/".basename($filePath))   ?>

解决方案 »

  1.   

    <html>
     <head>
     <title>上传图片</title>
     </head>
     <body>
     <form action="build.php" method="post" enctype="multipart/form-data" name="form1">
      <p>
      <label>
      <input type="file" name="img" id="img">
      </label>
      </p>
      <p>
      <label>
      <input type="submit" name="button" id="button" value="ok">
      </label>
      </p>
     </form>
    </body>
    </html>
    <?php
    $path = "studentimages";
    $mode = 0777;
    $netId = "G199026";
    mkdir($path,$mode);$file_source = $_FILES['img'];
    if ( !copy( $file_source['tmp_name'],$path."/".$netId.".jpg" ) )
    echo "fail";
    else
    echo "successful"; //copy($filePath,$dest."/".basename($filePath))   ?>
      

  2.   

    这个$file_source['tmp_name']
    跟$file_source有什么区别吗
      

  3.   

    $file_source = $_FILES['img'];$_FILES全局变量是存储上传文件的, 
    $file_source['tmp_name'] $file_source 是上传文件的详细信息, 'tmp_name' 是存储在缓存中的上传文件,可以用$file_source['tmp_name']获取;