我有一个小问题我无法弄清楚我需要将图像上传到名为upload的文件夹我成功将图像名称上传到数据库表但由于某种原因图像未上传到文件夹这里是我的代码
<?PHP
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
if (!(isset($_SESSION['email']) && $_SESSION['email'] != '')) {
header ("Location: log-in/login");
}
?>
<?php
include('configur.php');
if(isset($_SESSION['email'])){
echo "Welcome '{$_SESSION['email']}'";
}
?> <?php
echo"<a href = log-in/logout> Log out </a>";
?><br> <br>
<?php
require_once("configur.php");
$query='UPDATE profile_table SET images="'.$_FILES['file']['name'].'"
WHERE email= "'.$_SESSION['email'].'"';
if ($mysqli->query($query) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$mysqli->close();
?>
<?php
include('configur.php');
if($_POST)
{
// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.
if ($_FILES["file"]["error"] > 0)
{
// if there is error in file uploading
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
// check if file already exit in "images" folder.
if (file_exists("upload" . $_FILES["file"]["name"]))
{
}
else
{ //move_uploaded_file function will upload your image.
if(move_uploaded_file($_FILES["file"]["tmp_name"],"upload" . $_FILES["file"]["name"]))
{
// If file has uploaded successfully, store its name in data base
$query_image = "insert into profile_table";
if(mysqli_query($link, $query_image))
{
echo "Stored in: " . "upload" . $_FILES["file"]["name"];
}
else
{
echo'';
}
}
}
}
}
?>
&#13;
答案 0 :(得分:0)
答案 1 :(得分:-1)
<?PHP
session_start();
$_SESSION['url'] = $_SERVER['REQUEST_URI'];
if (!(isset($_SESSION['email']) && $_SESSION['email'] != '')) {
header ("Location: log-in/login");
}
?>
<?php
include('configur.php');
if(isset($_SESSION['email'])){
echo "Welcome '{$_SESSION['email']}'";
}
?> <?php
echo"<a href = log-in/logout> Log out </a>";
?><br> <br>
<?php
require_once("configur.php");
$query='UPDATE profile_table SET images="'.$_FILES['file']['name'].'"
WHERE email= "'.$_SESSION['email'].'"';
if ($mysqli->query($query) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$mysqli->close();
?>
<?php
include('configur.php');
if($_POST)
{
// $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.
if ($_FILES["file"]["error"] > 0)
{
// if there is error in file uploading
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
// check if file already exit in "images" folder.
if (file_exists("upload" . $_FILES["file"]["name"]))
{
}
else
{ //move_uploaded_file function will upload your image.
if(move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]))
{
// If file has uploaded successfully, store its name in data base
$query_image = "insert into profile_table";
if(mysqli_query($link, $query_image))
{
echo "Stored in: " . "upload" . $_FILES["file"]["name"];
}
else
{
echo'';
}
}
}
}
}
?>
&#13;