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 ...