Call uploaded PHP file.

edited May 2008 in Internet & Media
guys guys..
i have this problem.. here's the case:

1) Form in HTML includes a Attachment file.
2) Upon submit, it goes into Preview page in PHP.
3) After confirming the data user click on submit again which will then send out the information to the intended person mailbox by another PHP file.

Now question, how do i add the Attachment into the mail at step 3?
I can however do so if there isn't step 2.

Comments

  • LincLinc Owner Detroit Icrontian
    edited May 2008
    In step two, you need to move_uploaded_file to a temporary folder and pass its locations/filename to step three (I recommend using a session variable).
  • edited May 2008
    ok i tried but i dun get it.. need some advice here.

    Step 2 PHP code included the below:
    <?php session_start(); ?>
    <?php
    $_SESSION = 5;
    ?>

    ?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES); $_FILES; ?>
    <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES); $_FILES; ?>

    Step 3 PHP code
    $fp = fopen($target_path, "rb"); //Open it
    $data = fread($fp, filesize($target_path)); //Read it
    $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
    fclose($fp);

    tested but still not working..
  • LincLinc Owner Detroit Icrontian
    edited May 2008
    You've done neither of the two things I suggested: use move_uploaded_file to move $_FILES to a new location, and save that location as a session variable. Regular variables like $target_path reset every time the script is run. A session variable stays the same between scripts during the session, but you have to call session_start.

    I don't mean to be rude, but I get the impression you need to work on you basic PHP chops before getting too much further. Check out the PHP books on my recommended reading list.
  • edited May 2008
    thanks again that you pointed that error out.
    i managed to resolved it. using the below code out..

    [PHP]<?php
    $uploaded_dir = "uploads/";
    $filename = $_FILES["attachment"]["name"];
    $path = $uploaded_dir . $filename; print "Temporary name: " . $_FILES . "<br>";
    print "Original name: $filename<br>";
    print "Destination: $path<br>"; if (move_uploaded_file($_FILES["attachment"]["tmp_name"], $path)) {
    print "Uploaded file moved";
    // do something with the file here
    } else {
    print "Move failed";
    }
    ?>[/PHP]

    followed by:

    [PHP]<?php session_start();
    $_SESSION=$path;
    $_SESSION=$filename;
    ?>[/PHP]

    at first i made a stupid mistake of adding ' at the start and end of session settings. done with it and thanks.
Sign In or Register to comment.