我试图将文件上传到上传文件夹,但收到失败消息

时间:2015-06-15 09:35:50

标签: php

我的目录看起来像这样 - >源文件    --css    --upload    add_file.php    upload.php的

我的代码如下

upload.php的

 <form role="form" method="post" enctype="multipart/form-data" action="add_file.php">
                <div class="form-group">
                    <label for="filecaption">
                        Caption :
                    </label>
                    <input type="text" name="f_caption" class="form-control"/>
                </div>

                <div class="form-group">
                    <label for="Choose a File">
                        Caption :
                    </label>
                    <input type="file" name="uploaded_file" class="form-control"/>
                </div>

                <div class="form-group">

                    <input type="submit" name="upload" value="Upload" class="form-control btn btn-warning"/>
                </div>
            </form>

add_file.php

<?php



if(isset($_FILES['uploaded_file']))
{    
    $f_name= $_FILES['uploaded_file']['name'];
    $temp_name= $_FILES['uploaded_file']['tmp_name'];

if(!$temp_name)
{
    die("no file uploaded..please try again");
}
else
{
    $path = "upload/" . $f_name;
   if( move_uploaded_file($f_name, $path))
   {
       echo "success";
   }
   else
   {
       echo "failure";
   }
}
}
?>

1 个答案:

答案 0 :(得分:0)

问题来自add.php。

试试这个

<?php
if(isset($_FILES['uploaded_file'])) {

$f_name= $_FILES['uploaded_file']['name'];
$temp_name= $_FILES['uploaded_file']['tmp_name'];

if(!$temp_name)
{
    die("no file uploaded..please try again");
}
else
{
    $path = "upload/" . $f_name;
   if( move_uploaded_file($temp_name, $path))
   {
       echo "success";
   }
   else
   {
       echo "failure";
   }
}
}

&GT;

问题是你是从f_name而不是temp_location移动的。