SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem doing file upload

    Hi the following segment of code produces the error
    "Notice: Undefined variable: root ...."

    I have used this before on other servers but now I am on a shared server with php 5+
    any thoughts welcome

    ---------code--------------------------
    if( isset($_FILES['resume']) ){

    $uploaddir = $root.'/files/attachment/';
    $uploadfile = $uploaddir . basename($_FILES['resume']['name']);


    if (move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";

    } else {
    echo "Possible file upload attack!\n";
    }
    }

  2. #2
    SitePoint Enthusiast ro88o's Avatar
    Join Date
    Jun 2006
    Location
    Manchester, UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To diagnose this people will need your whole code rather than a snippet. Where is your variable $root defined?
    www.nubornis.com
    Web Development from Nuborn Internet Services

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    require_once("libmail.php");
    $mfname =$_POST["firstname"];
    $mlname = $_POST["surname"];
    $memail = $_POST["email"];
    $mphone = $_POST["phone"];

    $postcode = $_POST["postcode"];
    $address = $_POST["street"];

    $permission = $_POST["permission"];

    if( isset($_FILES['resume']) ){
    $uploaddir = $root.'/files/attachment/';
    $uploadfile = $uploaddir . basename($_FILES['resume']['name']);

    if (move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
    } else {
    echo "Possible file upload attack!\n";
    }
    }



    $message = "<h2>CONTACT INFORMATION</h2><br>";
    $message.= "<b>First name</b>: ".$mfname."<br>";
    $message.= "<b>Last name</b>: ".$mlname."<br>";
    $message.= "<b>Email</b>: ".$memail."<br>";
    $message.= "<b>Phone number</b>: ".$mphone."<br>";
    $message.= "<b>Address</b>: ".$address."<br>";
    $message.= "<b>Postcode</b>: ".$postcode."<br>";

    $message.= "<b>Permission</b>: ".$permission."<br>";
    $message.= "<b>Date Time</b>: ".strftime("%b %d %Y %X")."<br>";


    $m= new Mail; // create the mail

    $emails = array("bill@abc.com.au");

    $m->To( $emails );

    $m->Subject( "Our Subject" );


    $m->Body( $message); // set the body

    if( isset($_FILES['resume']) ){

    if (is_file($uploadfile)){
    $m->Attach( $uploadfile ) ;
    }
    }

    if($_POST['submit'] =="Send"){
    $m->From($memail);
    $m->Send(); // send the mail

    if( isset($_FILES['resume']) ){
    if (is_file($uploadfile)){
    @unlink($uploadfile); // delete file after attaching successfully
    }
    }



    header("location:thankyou.html");
    exit;


    }
    ?>

  4. #4
    SitePoint Enthusiast ro88o's Avatar
    Join Date
    Jun 2006
    Location
    Manchester, UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where's the $root variable actually set?
    This could be an issue with your register_globals value being different now you are on a different server, do you know what it was on your other server and what it is now?
    www.nubornis.com
    Web Development from Nuborn Internet Services

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought $root was a built in thing?
    Unfortunately I dont have access to the other server this worked on.

  6. #6
    SitePoint Enthusiast ro88o's Avatar
    Join Date
    Jun 2006
    Location
    Manchester, UK
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wilbur99 View Post
    I thought $root was a built in thing?
    I've never come across it before but I could be wrong.
    What happens if you add the following to your PHP file after require_once("libmail.php");:
    PHP Code:
    $root getenv("DOCUMENT_ROOT"); 
    www.nubornis.com
    Web Development from Nuborn Internet Services

  7. #7
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou

    I had a wrong path as I wasn't in the root of the website

    --------------------------------------
    require_once("libmail.php");


    $scriptPath = $_SERVER["SCRIPT_FILENAME"];
    $items=split("/",$scriptPath); // splitting the array
    $scriptName = array_pop($items);// remove the ourscript.php off the end
    $ourpath = implode ( "/" , $items ) . "/"; // rebuild our path

    ------------------------------------------

    Still learning, thanks heaps


Bookmarks

Posting Permissions

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