1

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");
    }    
?>
3
  • show your html code Commented Apr 21, 2018 at 10:41
  • Are you getting any error? Commented Apr 21, 2018 at 11:07
  • Simple one. do not name button to submit. replace with other name because some times button with name submit not working. Commented Apr 21, 2018 at 13:40

2 Answers 2

1

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'])) 
Sign up to request clarification or add additional context in comments.

Comments

0

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'])) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.