Sonder Systems
Sonder Systems

Reputation: 69

Php Image Up load not working

I am trying to upload a image using PHP to a file, I am new to the langue so help is definitely appreciated. The image to be uploaded comes from a page with a from input, the code just doesn't seem to be executing! Thanks so much and here is my code (first html, second php): I am trying to upload a image using PHP to a file, I am new to the langue so help is definitely appreciated. The image to be uploaded comes from a page with a from input, the code just doesn't seem to be executing! Thanks so much and here is my code (first html, second php):

<?php
    include_once 'Includes/dbh.inc.php';
    session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $_SESSION['user']; ?></title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Tajawal|Quicksand|Raleway:100" rel="stylesheet">
<link rel="stylesheet" tyle="text/css" href="main.css">
</head>
<body>
    
<!-- START Header -->
    
    <section class="headuser">
        <div class="pagetitle">
            C A T C H Y .
        </div>
        
        <div class="username">
            <a href="UserProfile.php"><?php echo $_SESSION['user']; ?></a>  
        </div>
    </section>          
<!-- END Header -->

<!-- START Bio -->
    <section class="Bio">
        <div class="friends">
            <br>freinds<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
        </div>  

        <div class="editbio">
            <?php echo $_SESSION['user']; ?>
            
            <form action="Includes/upload.php" id="bioimage" method="POST" enctype="multipart/form-data">
                <input type="file" name="profileup">
                <button type="submit" id = "submit" name="upload">Use!</button>
            </form>
            <form action="Includes/Post.inc.php" id="bioform" method="POST">
                <textarea name="Text1" id= "content" placeholder="Tell everyone who you are" cols="50" rows="10"></textarea>
                <br>
                <button type="submit" id="submit" name="submit">Post!</button>
            </form>
        </div>
    </section> 
<!-- END Bio -->
</body>
</html>

    if(isset($_POST['submit'])) {
            $file = $_FILES['profileup'];

            $fileName = $_FILES['profileup']['name'];
            $fileTmpName = $_FILES['profileup']['tmp_name'];
            $fileSize = $_FILES['profileup']['size'];
            $fileError = $_FILES['profileup']['error'];
            $fileType = $_FILES['profileup']['type'];

            $fileExt = explode('.', $fileName);
            $fileActualExt = strtolower(end($fileExt));

            $allowed = array('jpg', 'jpeg', 'png');

            if (in_array($fileActualExt, $allowed)){

                if ($fileError === 0){

                    if ($fileSize < 1000000){
                        $filenamenew = uniqid('', true).".".$fileActualExt;
                        $filedest = 'profileimages/'.$filenamenew;
                        move_uploaded_file($fileTmpName, $filedest);
                        header("Location: ../UserProfile.php?suc");
                    }else{
                        echo "your file was to big";
                    }

                }else{
                    echo "There was an error uploading your file";
                }

            }else{
                echo "you cant upload files of this type";
            }
    }else{
        header("Location: ../UserProfile.php?fail");
    }    
?>

Upvotes: 1

Views: 82

Answers (2)

Shohidur Rahman
Shohidur Rahman

Reputation: 71

I think you can use your button name "upload".

if(isset($_POST['submit']))

when you submit an image it must be working.

if(isset($_POST['upload'])) 

Upvotes: 1

jasinth premkumar
jasinth premkumar

Reputation: 1413

problem for not execution of php script in upload page is tthis line

if(isset($_POST['submit'])

because this check input submit is set in your html you have named submit button as upload

solution change name ofhttml buttton to submitt or change if condition to this

if(isset($_POST['upload'])) 

Upvotes: 0

Related Questions