【问题标题】:Take image URL and send to database获取图像 URL 并发送到数据库
【发布时间】:2014-01-05 04:59:10
【问题描述】:

JavaScript

<script>
function readURL(input) {
    if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function (e) {
        $('#blah').attr('src', e.target.result)
                  .width(150)
                  .height(200);
        };

        reader.readAsDataURL(input.files[0]);
    }
}
</script>

PHP

if($_POST) {
    $image = $_POST["image"];
    $pro_name = $_POST["pro_name"];
    $pro_desc = $_POST["pro_desc"];
    $price = $_POST["price"];
    $categories = $_POST["categories"];
    $stock = $_POST["stock"];

    $ekle=mysql_query("insert into product (`product_id`,`pro_name`,`pro_desc`,`price`,`categories`,`image`,`stock`) 
                       VALUES (NULL, '$pro_name','$pro_desc','$price','$categories','$image','$stock')");
    if($ekle) {
        echo "<script>alert('Product Added Succecfully.');window.location='add_pro.php'</script>";
    } else {
        echo "<script>alert('Unexpected Error, plase try again.');window.location='add_pro.php'</script>";
    }
}

HTML

<td width="175" height="225"><img id="blah" src="#" alt="your image" /></td>
<td><input type='file' onchange="readURL(this);" name="image" value=""/></td>

此 HTML 部分显示页面上的图像,我需要获取图像 URL 并将其发送到数据库,但我不知道如何在 JavaScript 中执行此操作。

【问题讨论】:

标签: javascript php jquery html


【解决方案1】:

您当前的 PHP 代码:

 $image = $_POST["image"];

未使用正确的语法。(将 $_POST["image"]; )更改为 $_FILE["image"];)。

试试这个:

 $image = $_FILE["image"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 2020-03-09
    • 1970-01-01
    相关资源
    最近更新 更多