dpkk8687 2014-03-24 07:45
浏览 12
已采纳

PHP图像上传失败

I really need your help. I am trying to upload an image with php code. When I use different .php file with only upload code, it works, but when I try to add to my main code where I have this information which is posted into database.

I have this added and as I said it works with separate code only for upload.

form action="core/books-reg.php" method="POST" enctype="multipart/form-data"

This is my main .php code in where I want to make it work. Code starts after !empty(Description). The database takes the name and puts in mysql but there is no file in my folder. any help or other method would be really good.

<?php
session_start();

require("dbc.php");

$username = $_SESSION['username'];
$title = $_POST['title'];
$con = $_POST['con'];
$price = $_POST['price'];
$prodcode = $_POST['prodcode'];
$isbn = $_POST['isbn'];
$publisher = $_POST['publisher'];
$pages = $_POST['pages'];
$description = $_POST['description'];
$year = $_POST['year'];
$course = $_POST['course'];
$module = $_POST['module'];

if(!empty($title))
{
    if(!empty($price))
    {
        if(!empty($prodcode))
        {
            if(!empty($isbn))
            {
                if(!empty($publisher))
                {
                    if(!empty($pages))
                    {
                        if(!empty($description))
                        {
                            if (!isset($_FILES['image']['tmp_name'])) {
                            echo "";
                            }else{
                            $file=$_FILES['image']['tmp_name'];
                            $image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
                            $image_name= addslashes($_FILES['image']['name']);

                            move_uploaded_file($_FILES["image"]["tmp_name"],"upload/" . $_FILES["image"]["name"]);

                            $location="upload/" . $_FILES["image"]["name"];             
                            }

                            mysql_query("INSERT INTO `books` (username,title,con,price,prodcode,isbn,publisher,pages,description,image,year,course,module) VALUES('$username','$title','$con','$price','$prodcode','$isbn','$publisher','$pages','$description','$image_name','$year','$course','$module')");
                            header("location: ../add_books.php?feedback=Your book has been put on the books page.");
                        }
                        else
                        {
                            header("location: ../add_books.php?feedback=Description field is empty");
                        }
                    }
                    else
                    {
                        header("location: ../add_books.php?feedback=Pages field is empty");
                    }
                }
                else
                {
                    header("location: ../add_books.php?feedback=Publisher field is empty");
                }
            }
            else
            {
                header("location: ../add_books.php?feedback=ISBN field is empty");
            }
        }
        else
        {
            header("location: ../add_books.php?feedback=Product code field is empty");
        }
    }
    else
    {
        header("location: ../add_books.php?feedback=Price field is empty");
    }
}
else
{
    header("location: ../add_books.php?feedback=Title field is empty");
}   
?>
  • 写回答

2条回答 默认 最新

  • douliao5942 2014-03-24 09:12
    关注

    if u want to place the upload code on same page then firstly you don't need to specify the action in the form tag.

    And check that the path upload/ is at the correct place exists or not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错