<?  
//  viewforum.php  
//  Case  Study  3:  Forum  -  Foundation  PHP  for  Flash  
include('common.php');  
 
//******************************************  
 
//  Connect  to  database  
$link  =  dbConnect();  
//  Include  config  file  
//$password  =  md5($pass);  
$userID=1;  
 
$posted  =  time();  
 
//  Build  and  execute  query  to  insert  new  thread  
$query  =  "INSERT  INTO  forumThreads  (userID,lastPost,pi)  VALUES  ($userID,$posted,1)";  
if(!mysql_query($query))  {  
       fail("Error  inserting  thread");  
}  
 
$threadID  =  mysql_insert_id();  
 
$query  =  "INSERT  INTO  forumPosts  (threadID,  userID,  message,  posted,pi,pic)  VALUES($threadID,  $userID,  '$message',  $posted,1,'$imagefile_name')";  
if(!mysql_query($query))  {  
       fail("Error  inserting  post");  
}  
//$query2="select  pic  from  forumposts  where  userID=$userID";  
//if(!mysql_query($query2)){  
   //    echo("Error  select  data");  
       //exit;  
//}  
mysql_close($link);  
if($submit){  
           copy($imagefile,'/home/httpd/vhosts/icons-online.com/httpdocs/$imagefile_name');  
           unlink($imagefile);  
           echo  "You  have  just  uploaded  $imagefile_name";  
           }else{  
                       echo  "You  did  not  upload  any  file";  
                       }  
?>  
<html><head><title>&Eacute;&Iuml;&Ocirc;&Oslash;&Icirc;&Auml;&frac14;&thorn;±í&micro;&yen;</title></head>    
 
<head>  
<title>fdsafsad</title>  
</head>  
<body>  
<table>  
<form  enctype="multipart/form-data"  name=myform  action="<?php  echo  $php_self?>"  method="post">  
<tr><td>choose  file</td></tr><input  name="imagefile"  type="file">  
<input  type="hidden"  name="max_file_size"  value="100000">  
</td></tr>  
<tr><td  col  span="2">  <input  name="submit"  value="submit"  type="submit"></td></tr>  
</form></table></body>  
 
</html> 错误信息:得不到imagefile的值

解决方案 »

  1.   

    是文件上传出错 应该是copy那句出错了  你把那个值输出来看看是不是空值  然后你看一下你要写的那个目录的chomd 是不是可写的  确定服务器允许你上传文件吗?
      

  2.   

    上传的文件变量最好用下面的数组.因为在PHP4.3..后register_globals的默认值为Off$_FILES['imagefile']['name']   代替原来的$imagefile_name
    客户端机器文件的原名称。 $_FILES['imagefile']['type']   代替原来的$imagefile_type
    文件的 MIME 类型,需要浏览器提供该信息的支持,例如“image/gif”。 $_FILES['imagefile']['size']   代替原来的$imagefile_size
    已上传文件的大小,单位为字节。 $_FILES['imagefile']['tmp_name']   代替原来的$imagefile
    文件被上传后在服务端储存的临时文件名。 $_FILES['imagefile']['error']
    和该文件上传相关的错误代码。['error'] 是在 PHP 4.2.0 版本中增加的。 一般的表单变量用$_POST['名称'] 如:$submit ===>$_POST['submit'].