file upload in php

Discussion in 'PHP' started by parkerproject, May 7, 2008.

  1. #1
    i need help with my upload script..because it is not uploading file to the folder on my website

    see the whole code below
    
    
    <form action="homework.php" enctype="multipart/form-data" method="post">
       Last Name:<br /> <input type="text" name="name" value="" /><br />
       Homework:<br /> <input type="file" name="homework" value="" /><br />
       <p><input type="submit" name="submit" value="Submit Notes" /></p>
    </form>
    
    <?php
    
       # Set a constant
      define ("FILEREPOSITORY",$_SERVER['parker/recruitment']."/resume");  
    
    
       if (isset($_FILES['homework'])) {
    
          if (is_uploaded_file($_FILES['homework']['tmp_name'])) {
    
             if ($_FILES['homework']['type'] != "application/msword") {
                echo "<p>Homework must be uploaded in WORD format.</p>";
             } else {
                /* Format date and create daily directory, if necessary. */
                $today = date("m-d-Y");
                if (! is_dir(FILEREPOSITORY)) {
                   mkdir(FILEREPOSITORY);
                }
    
                /* Assign name and move uploaded file to final destination. */
                $name = $_POST['name'];
                $result = move_uploaded_file($_FILES['homework']['tmp_name'], FILEREPOSITORY."/"."$name.doc");
    
                /* Provide user with feedback. */
                if ($result == 1) 
                   echo "<p>File successfully uploaded.</p>";
                else 
                   echo "<p>There was a problem uploading the homework.</p>";
             }
          }
       }
    ?>
    
    PHP:

     
    parkerproject, May 7, 2008 IP
  2. CPURules

    CPURules Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ("FILEREPOSITORY",$_SERVER['parker/recruitment']

    I don't understand $_SERVER['parker/recruitment'].
     
    CPURules, May 7, 2008 IP
  3. parkerproject

    parkerproject Active Member

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    98
    #3
    ("FILEREPOSITORY",$_SERVER['parker/recruitment']

    the code above is just the path to the folder of my website
     
    parkerproject, May 7, 2008 IP
  4. pophysis

    pophysis Peon

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    did you set the correct permissions on the folder?
     
    pophysis, May 7, 2008 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    try putting ur folder name into static

    $directory = "app/file/subfolder";

    where you want to put the file..
    just for conformation
     
    bartolay13, May 7, 2008 IP
  6. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #6
    tamilsoft, May 8, 2008 IP
  7. parkerproject

    parkerproject Active Member

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    98
    #7
    I have been able to use another code and is working fine
    also I was wondering ,if i want to provide a user with a link to its CV in the folder,so that a user can always click on a link to open his current cv ..how can i do that

    THANKS
     
    parkerproject, May 8, 2008 IP
  8. dean5000v

    dean5000v Peon

    Messages:
    201
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    im not brilliant at php, but i guess you could use something like this.

    	 print "<a href=\"http://www.yourdomain.com/FILEREPOSITORY/" . $HTTP_POST_FILES['homework']['name'] . ".doc" "\">View your file</a>";
    Code (markup):
     
    dean5000v, May 9, 2008 IP