php 文件上传,echo tmp_name ,$_FILES["news_file"]['name'];都没有值
<formaction='./news_save.php'method='post'>标题:<inputclass='header_one_news_add'type='...
<form action='./news_save.php' method='post' >
标题:<input class='header_one_news_add' type='text' name='title'/><br />
内容:<textarea cols='60' rows='16' name='content' ></textarea><br />
类别:<select name='category_id' size='1'>
<?php
get_connection();
$result_set=mysql_query('select * from category');
close_connection();
while($row=mysql_fetch_array($result_set)){
?>
<option value='<?php echo $row["caregory_id"]; ?>'><?php echo $row['name'];?></option>
<?php
}
?>
</select><br />
附件:<input type='file' name='news_file' size='50'/>
<input type='hidden' name='MAX_FILE_SIZE' value='10485760'/><br />
<input type='submit' value='提交'><input type='reset' value='重置'>
</form>
==================
<?php
function upload($file,$file_path){
$error=$file['error'];
echo $error;
switch ($error){
case 0:
$file_name=$file['name'];
echo '<br />'.'++++++++++++++';
$file_temp=$file['tmp_name'];
echo $file_name;
echo $file_temp;
echo '%%%%%%%%%%%%';
$destination=$file_path.'/'.$file_name;
echo $destination;
move_uploaded_file($file_temp,$destination);
return '文件上传成功!';
case 1:
<?pinclude_once('functions/file_system.php');if(empty($_POST)){ $message='上传的文件超过了php.ini中post_max_size选项限制的值';}else{ $user_id=1; $category_id=$_POST['category_id']; $title=$_POST['title']; $content=$_POST['content']; $currentdate=date('y-m-d h:i:s'); $clicked=0; $file_name=$_FILES["news_file"]['name']; echo $_FILES["news_file"]['name']; echo '@@@@@@@@@@@','<br />';echo $file_name;echo '99999999999999999999999999999'; $message=upload($_FIL 展开
标题:<input class='header_one_news_add' type='text' name='title'/><br />
内容:<textarea cols='60' rows='16' name='content' ></textarea><br />
类别:<select name='category_id' size='1'>
<?php
get_connection();
$result_set=mysql_query('select * from category');
close_connection();
while($row=mysql_fetch_array($result_set)){
?>
<option value='<?php echo $row["caregory_id"]; ?>'><?php echo $row['name'];?></option>
<?php
}
?>
</select><br />
附件:<input type='file' name='news_file' size='50'/>
<input type='hidden' name='MAX_FILE_SIZE' value='10485760'/><br />
<input type='submit' value='提交'><input type='reset' value='重置'>
</form>
==================
<?php
function upload($file,$file_path){
$error=$file['error'];
echo $error;
switch ($error){
case 0:
$file_name=$file['name'];
echo '<br />'.'++++++++++++++';
$file_temp=$file['tmp_name'];
echo $file_name;
echo $file_temp;
echo '%%%%%%%%%%%%';
$destination=$file_path.'/'.$file_name;
echo $destination;
move_uploaded_file($file_temp,$destination);
return '文件上传成功!';
case 1:
<?pinclude_once('functions/file_system.php');if(empty($_POST)){ $message='上传的文件超过了php.ini中post_max_size选项限制的值';}else{ $user_id=1; $category_id=$_POST['category_id']; $title=$_POST['title']; $content=$_POST['content']; $currentdate=date('y-m-d h:i:s'); $clicked=0; $file_name=$_FILES["news_file"]['name']; echo $_FILES["news_file"]['name']; echo '@@@@@@@@@@@','<br />';echo $file_name;echo '99999999999999999999999999999'; $message=upload($_FIL 展开
展开全部
用表单上传文件时,一定要设置表单的enctype为multipart/form-data,否则无法上传文件。这也是新手容易犯的错误。
1 | < form method = "post" enctype = "multipart/form-data" ></ form > |
enctype指的是表单数据的MIME类型。其含义简单的说是指定数据的“媒体”类型。比如GIF图片的MIME类型为image/gif。可以让解析/播放程序识别它的类型并使用相应的方式处理。
enctype的默认值为“application/x-www-form-urlencoded”,它表示经过转义后的表单文本数据。而multipart/form-data表示表单可以包含一些特殊类型的数据。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询