dongying9756 2017-02-04 06:41
浏览 43

图像未移动到文件夹

I am trying to upload an image and move to a folder in my root directory, but nothing is happening. When I tried to make the directory from php itself, the folder wasn't created either. Now I made the folder and tried to upload but still nothing happens. I have another website which in which it creates a folder and uploads an image to it and that works fine. I tried copying the exact code from that and using it, but still nothing happens. (I am still learning and I am running this on WAMP server on Windows)

Here is the HTML

<form method="post" action="?pg=editmovie&act=1" enctype="multipart/form-data">

<p class="formtext" id="topttx"> Film title </p>
<input type="text" name="title" id="topbox">

<p class="formtext" id="sttx">Director </p>
<input type="text" name="dir" id="sbox">

<p class="formtext" id="sttx">Actor 1 </p>
<input type="text" name="act1" id="actbox">

<p class="formtext" id="sttx">Actor 2 </p>
<input type="text" name="act2" id="actbox">

<p class="formtext" id="sttx">Actor 3 </p>
<input type="text" name="act3" id="actbox">

<p class="formtext" id="sttx">Genre </p>
<input type="text" name="gre" id="grbox">

<p class="formtext" id="yrtxt">Year </p>
<input type="text" name="yr" id="yrbox">

<p class="formtext" id="sttx">Film cover </p>
<input type="file" name="img">

<input type="submit" value="Add Film" name="sub">

</form>

and the PHP

function act1()
{
if(isset($_POST['sub']))
{
    $tle = $_POST['title'];
    $dir = $_POST['dir'];
    $a1 = $_POST['act1'];
    $a2 = $_POST['act2'];
    $a3 = $_POST['act3'];
    $gre = $_POST['gre'];
    $yr = $_POST['yr'];

    $conn = getDBConn();
    $sql = "INSERT INTO movies(title, director, act_1, act_2, act_3, genre, year) VALUES('$tle','$dir','$a1','$a2','$a3','$gre','$yr')";
    $output = mysqli_query($conn,$sql);

    $dir = "images/films/";
    $imno = mysqli_insert_id($conn);

    $src = $_FILES['img']['tmp_name'];
    $des = $dir.$imno;
    move_uploaded_file($src,$des);
}

if($output==1)
{
    echo 'Data Stored';
}
else
{
    echo 'Data Not Stored ';
    echo mysqli_error($conn);
}
}
?>

**********Sorry guys, it is working properly, I have given the linked a different page in my form action so that's why it wasn't working

  • 写回答

2条回答 默认 最新

  • doulai6469 2017-02-04 07:07
    关注

    Please try to change code of move_upload_file() like this it's display error if any problem in image.

    if (move_uploaded_file($src,$des);) {
        echo 'Received file' . $_FILES['file']['name'] . ' with size ' . $_FILES['file']['size'];
    } else {
        echo 'Upload failed!';
    
        var_dump($_FILES['file']['error']);
    }
    

    please read this for more information File upload Error handling and also for get specific error specific error

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序