www.webdeveloper.com
Results 1 to 7 of 7

Thread: How do I make this Form, in this PHP file, accessible via an html page?

  1. #1
    Join Date
    Feb 2005
    Posts
    51

    How do I make this Form, in this PHP file, accessible via an html page?

    How do I make the Form in this PHP file accessible via an html page, so that it still works successfully with this PHP file? Here's the php file code:
    Code:
    <?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");
    $extension = end(explode(".", $_FILES["file"]["name"]));
    if (($_FILES["file"]["size"] < 524288000) && 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 in S3 Bucket.";
    } 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 file of maximum size 5 MB.";
    }
    }
    ?>
    
    <?php
    require_once 'header.php';
    ?>
    <fieldset>
    <legend>PHP AWS S3 integration library Demo1</legend>
    Description: In this demo a file is being upload to an S3 bucket using "PHP AWS S3 integration library". After upload you can check the uploaded file in below table.
    If you require some manipulation before uploading file to S3 then check <a href="upload_file_manually.php">Demo2</a> <br />
    <br />
    
     
    <form action="" 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
    if ($message != "" || @$_SESSION['message'] != "") {
    ?>
    <div class="alert alert-success">
    <?php echo $message; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <?php
    echo @$_SESSION['message'];
    @$_SESSION['message'] = '';
    ?>
    </div>
    <?php
    }
    ?>
    <div>
    <table class="table table-hover">
    <caption>
    <strong>Last 10 user uploaded files</strong>
    </caption>
    <?php
    $files_result = mysql_query("SELECT * from `phps3files` WHERE type LIKE 'file' ORDER by id DESC LIMIT 10");
    $i = 1;
    while ($file = mysql_fetch_object($files_result)) {
    ?>
    <tr>
    <td><?php echo $i++; ?></td>
    <td><a href="<?php echo site_url_s3("uploads/" . $file->file); ?>" target="_blank">View/Download</a> </td>
    <td><a href="<?php echo site_url("delete_file.php?id=" . $file->id); ?>">Delete file from S3</a></td>
    <td><?php echo "Uploaded by: " . $file->user_name; ?></td>
    </tr>
    <?php
    }
    if ($i == 1) {
    ?>
    <tr>
    <td colspan="2"> No files uploaded yet</td>
    </tr>
    <?php
    }
    ?>
    </table>
    </div>
    <h4>Source Code Part of Demo</h4>
    <pre class="prettyprint lang-php linenums">
    &lt;?php
    session_start();
    require_once 'phps3integration_lib.php';
    $message = &quot;&quot;;
    if (@$_POST['submit'] != &quot;&quot;) {
    $allowed_ext = array(&quot;gif&quot;, &quot;jpeg&quot;, &quot;jpg&quot;, &quot;png&quot;, &quot;pdf&quot;, &quot;doc&quot;, &quot;docs&quot;, &quot;zip&quot;);
    $extension = end(explode(&quot;.&quot;, $_FILES[&quot;file&quot;][&quot;name&quot;]));
    if (($_FILES[&quot;file&quot;][&quot;size&quot;] &lt; 524288000) &amp;&amp; in_array($extension, $allowed_ext)) {
    if ($_FILES[&quot;file&quot;][&quot;error&quot;] &gt; 0) {
    //$message.=&quot;There is some error in upload, see: &quot; . $_FILES[&quot;file&quot;][&quot;error&quot;] . &quot;&lt;br&gt;&quot;;//Enable this to see actual error
    $message.=&quot;There is some error in upload. Please try after some time.&quot;;
    } else {
    $uploaded_file = uploaded_file_to_s3($_FILES[&quot;file&quot;], &quot;uploads&quot;, true);
    if ($uploaded_file != FALSE) {
    $user_name = @$_POST['user_name'] != &quot;&quot; ? @$_POST['user_name'] : &quot;Anonymous&quot;;
    $form_data = array(
    'file' =&gt; $uploaded_file,
    'user_name' =&gt; $user_name,
    'type' =&gt; 'file'
    );
    mysql_query(&quot;INSERT INTO `phps3files` (`id`, `file`, `user_name`, `type`) VALUES (NULL, '&quot; . $uploaded_file . &quot;', '&quot; . $user_name . &quot;', 'file')&quot;) or die(mysql_error());
    $message.= &quot;File successfully uploaded in S3 Bucket.&quot;;
    } else {
    $message.=&quot;There is some error in upload. Please try after some time.&quot;;
    }
    }
    } else {
    $message.= &quot;Invalid file, Please upload a gif/jpeg/jpg/png/pdf/doc/docs/zip file of maximum size 5 MB.&quot;;
    }
    }
    ?&gt;
    </pre>
    <?php require_once 'footer.php'; ?>
    Thanks. Any help will be appreciated.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    898
    Tough to read and digest your code. BTW - structure and tabs/indentation help to make code much more readable.

    So - if I understand - you have an html form that you designed and wrote and it is in this script, mingled with your php. Now you want to use this EXACT (?) form in another PHP script? If that is correct, why not save the form code as a distinct file and use an include to include it in both of those scripts?

    If that is not what you meant, then I suggest you re-work your question.

  3. #3
    Join Date
    Feb 2005
    Posts
    51
    Thanks for your reply. This is a script I got, I didn't design it or write it. I don't want to use the form in another php script, I'd just like to put the form on an html page so I can style it. It works fine as is, I'd just like it on an html page. I don't know how to "save the form code as a distinct file and use an include to include". Any additional help will be appreciated.

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    898
    Begin with a new html document in your editor that has all the proper headings. (A 'file, new html template in your ide?) Then open up this script in your editor and cut and paste the part you want into the new template and upload it to your server? If you can't do that I'm afraid I can't help you with something that elemental.

  5. #5
    Join Date
    Feb 2005
    Posts
    51
    Thanks for your reply.
    Yes, I can do that (except what is an ide?). I just assumed that the html part that is cut(and separated to it's own html), had to have added code to refer back to the functions in the php file. Someone suggested "alter the <form> tag's 'action' element in the .html file to target the php file". And i don't know hwo to alter that.
    Any additional guidance will be appreciated.

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    898
    You didn't say you wanted to include php functionality. You said " form" which is an entirely-html entity.

    So - you're not a programmer. Why then are you involving yourself in something that is definitely a programmer's work description?

    BTW - the form in the original script IS on an html page, otherwise you would never see the form in use.

  7. #7
    Join Date
    May 2014
    Posts
    77
    If you pull the HTML out, you'll start to lose functionality, like error reporting.

    I recommend you make a backup of the file and then just start by changing the bits of HTML you recognise.

    Just don't touch anything between the <?php .... ?> as this is PHP code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles