PHP - 上传照片

PHP-newbie here

I'm trying to make a simple script to upload a photo to my data-base. I know it's not very efective, but I want to do it anyway.

So I have these two .php files:

<html>
<body>
    <form action="upload.php">
        <input type="file" name="photo">
        <input type="submit" name="submit" value="Submit" />
    </form>
</body>

and

<?php

error_reporting( error_reporting() & ~E_NOTICE );

$conn = mysqli_connect("localhost", "root", "", "poze");

if(!$conn){
    die("Connection failed: ".mysqli_connect_error());
}
else echo "Succes";

$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
//$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
//$imageType = mysql_real_escape_string($_FILES["image"]["type"]);

if($imageName==NULL){
    echo "Null";
}
else{
    echo "The photo is okay!";
}

After uploading any kind of picture, it echoes out as empty.

Could, anyone explain me why? And how could I solve it?

PHP-newbie here

I'm trying to make a simple script to upload a photo to my data-base. I know it's not very efective, but I want to do it anyway.

So I have these two .php files:

<html>
<body>
    <form action="upload.php">
        <input type="file" name="photo">
        <input type="submit" name="submit" value="Submit" />
    </form>
</body>

and

<?php

error_reporting( error_reporting() & ~E_NOTICE );

$conn = mysqli_connect("localhost", "root", "", "poze");

if(!$conn){
    die("Connection failed: ".mysqli_connect_error());
}
else echo "Succes";

$imageName = mysql_real_escape_string($_FILES["image"]["name"]);
//$imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"]));
//$imageType = mysql_real_escape_string($_FILES["image"]["type"]);

if($imageName==NULL){
    echo "Null";
}
else{
    echo "The photo is okay!";
}

After uploading any kind of picture, it echoes out as empty.

Could, anyone explain me why? And how could I solve it?

SOLVING:

I changed the APIs so that I would only use mysqli

Index:

<html>
<body>
    <form enctype="multipart/form-data" action="upload.php" method="POST">
        <input type="file" name="photo">
        <input type="submit" name="submit" value="Submit" />
    </form>
</body>

PHP script:

<?php

error_reporting( error_reporting() & ~E_NOTICE );

$conn = mysqli_connect("localhost", "root", "", "poze");

if(!$conn){
    die("Connection failed: ".mysqli_connect_error());
}
else echo "Succes"."<br>";

$imageName = mysqli_real_escape_string($conn ,$_FILES["photo"]["name"]);
$imageData = mysqli_real_escape_string($conn, file_get_contents($_FILES["photo"]["tmp_name"]));
$imageType = mysqli_real_escape_string($conn, $_FILES["photo"]["type"]);

//process the image ...

first you must use this form element:

<form enctype="multipart/form-data" action="upload.php" method="POST">

and secondly you must read file content from temporary folder and save to DB:

$tmpName  = $_FILES['userfile']['tmp_name'];
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

then save this content to a field in mysql of type BLOB.