1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Form's messages isn't showing up on html page

Discussion in 'PHP' started by chrisj, Jun 16, 2014.

  1. #1
    I have an Upload Form.
    It uploads successfully currently, but there is no "File successfully uploaded" or "invalid file" messages showing after "Submit".
    Can you help me with that, please?
    Here are the html and php file code:

    
    <html>
    <head>Upload
    </head>
    <body>
    <?php require_once 'header.php'; ?>
    
    <fieldset>
    <form action="upload_file.php" method="post" enctype="multipart/form-data">
    
    <div class="control-group">
    <label for="file" class="control-label">Choose a file to upload: <span style="color:red">*</span></label>
    <div class='controls'>
    <input id="file" type="file" name="file" />
    <?php //echo form_error('file'); ?> </div>
    </div>
    
    <div class="control-group">
    <label for="user_name" class="control-label">Your name:</label>
    <div class='controls'>
    <input id="user_name" type="text" name="user_name" maxlength="255" value="" />
    
    <?php //echo form_error('user_name'); ?> </div>
    </div>
    
    <div class="control-group">
    <label></label>
    <div class='controls'>
    <input type="submit" name="submit" value="Submit" class="btn">
    </div>
    </div>
    </form>
    </fieldset>
    
    <?php echo "<div class=\"alert alert-success\">{$message}</div>"; ?>
    <div>
    <table class="table table-hover">
    
    <?php echo $file_list_HTML; ?>
    </table>
    </div>
    <pre class="prettyprint lang-php linenums">
    
    </pre>
    <?php require_once 'footer.php'; ?>
    
    </body>
    </html>
    
    Code (markup):
    PHP file:

    
    <?php
    session_start();
    require_once 'phps3integration_lib.php';
    $message = "";
    if (@$_POST['submit'] != "") {
    $allowed_ext = array("gif", "jpeg", "jpg", "png", "pdf", "doc", "docs", "zip", "flv", "mp4", "mov");
    $extension = end(explode(".", $_FILES["file"]["name"]));
    if (($_FILES["file"]["size"] < 32428800) && in_array($extension, $allowed_ext)) {
    if ($_FILES["file"]["error"] > 0) {
    //$message.="There is some error in upload, see: " . $_FILES["file"]["error"] . "<br>";//Enable this to see actual error
    $message.="There is some error in upload. Please try after some time.";
    } else {
    $uploaded_file = uploaded_file_to_s3($_FILES["file"], "uploads", true);
    if ($uploaded_file != FALSE) {
    $user_name = @$_POST['user_name'] != "" ? @$_POST['user_name'] : "Anonymous";
    $form_data = array(
    'file' => $uploaded_file,
    'user_name' => $user_name,
    'type' => 'file'
    );
    mysql_query("INSERT INTO `phps3files` (`id`, `file`, `user_name`, `type`) VALUES (NULL, '" . $uploaded_file . "', '" . $user_name . "', 'file')") or die(mysql_error());
    $message.= "File successfully uploaded.";
    } else {
    $message.="There is some error in upload. Please try after some time.";
    }
    }
    } else {
    $message.= "Invalid file, Please upload a gif/jpeg/jpg/png/pdf/doc/docs/zip/flv/mp4/mov file of maximum size 30 MB.";
    }
    }
    ?>
    Code (markup):
     

    Attached Files:

    Last edited: Jun 16, 2014
    chrisj, Jun 16, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Could you please edit your post and put the code in code-tags?
     
    PoPSiCLe, Jun 16, 2014 IP
  3. jworldwide

    jworldwide Active Member

    Messages:
    707
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Proper indention would help and make that a lot more readable.
     
    jworldwide, Jun 16, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    You can't show a message from another PHP-file in the file you're calling it from, unless you're passing information back and forth - which you aren't. You're passing the $_POST-variables to the upload_file.php-file - but the assignments in that file won't be possible to show in the form-file. For that to work you'll have to combine the two (ie, have the PHP-code in the same file as the form, and call on the $message after the upload succeeds or fails.
     
    PoPSiCLe, Jun 16, 2014 IP
  5. chrisj

    chrisj Well-Known Member

    Messages:
    606
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    Thanks for that reply. It was very helpful
     
    chrisj, Jun 16, 2014 IP