loose my mind loose my mind - 3 months ago 25
PHP Question

image cannot upload to folder

i have a small problem i cannot figure out i need to upload an image to a folder called upload i successfully uploaded the name of the image to database table but for some reason the image is not being uploaded to folder here is my code



<?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']}'";
}


?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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'';
}
}
}




}
}


?>




Answer

<?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']}'";
}

  
?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?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'';
 }
 }
 }

 


 }
 }


 ?>

Comments