SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Feb 2008
    Location
    Idaho Falls, Idaho
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_FILES['uploadedfile']

    Ok, im making a php script where I can upload a txt file for certain id in my db. I need help on the naming the file part. I want to name the txt file the same name as a certain field in a row. So I can keep track of my files better.

    I have my script set up so I can view all the rows in the db, I want to click on one of the rows and then be able to upload a file.

    How do I do this?

  2. #2
    SitePoint Addict
    Join Date
    Jun 2006
    Location
    Durban, South Africa
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which part are you struggling with exactly?

  3. #3
    Non-Member
    Join Date
    Feb 2008
    Location
    Idaho Falls, Idaho
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not trying to name the file the same name as a row anymore. Right now Im focusing on adding the txt file to the a certain row. Im trying to make it so I can click on a link, then upload a file, and that file will attach to the row. I then can download it later. Here is my code. It shows up completely white for me.

    PHP Code:
          <?php
    require_once('takenout...');

    //start grab id
    $ImageId mysql_escape_string(strip_tags($_GET['ImageId']));

    $sql "select * from image WHERE ImageId='$ImageId'";
    $result mysql_query($sql) or die(mysql_error()); 

    while (
    $row mysql_fetch_array($result,MYSQL_ASSOC)) 
        {
    //end grab id

    //file adding code
          
    if ($_POST['Submit']) {
            if (
    $_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
              
    //print_r($_FILES);
              
    $photo addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
    $_FILES['file']['size']));
               
    $query sprintf("UPDATE 'image' SET Image='%s',FileType='%s' WHERE ImageId='".mysql_escape_string($row['ImageId']."'"$photo$_FILES['file']['type'] );
               if (
    mysql_query($query)) {
                
    $messages[] = "Your files is successfully store in database"
               } else {
                
    $messages[]= mysql_error();
               }
              } else {
               
    $messages[]="The file is bigger than the allowed size please resize";
              }
            }

    }
    if (!
    is_numeric($ImageId)) {

    die (
    "Invalid ID");
    }
          
    ?>
          <html>
          <head>
          <title>Add Image</title>
          </head>    
          <body>
          <? 
          
    if (isset($messages)) { 
            foreach (
    $messages as $message) {
             print 
    $message ."<br>";
            } 
          }
          
    ?>
          <form action="" method="post" enctype="multipart/form-data" name="form1">
          <input type="file" name="file">
          <input type="hidden" name="MAX_FILE_SIZE" value="96000">
          <input type="submit" name="Submit" value="Submit">
          </form>
          </body>
          </html>

    The page that links to that page is:

    PHP Code:
    <a href='addfile.php?ImageId=$ImageId'>add txt file</a
    Also what is the code to show errors? thanks

  4. #4
    Non-Member
    Join Date
    Feb 2008
    Location
    Idaho Falls, Idaho
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone know?

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Location
    Sydney
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with this input field in the form

    <input type="file" name="file">

    $_FILES['file']['name'] will be the orginal filename as on your PC.

    the uploaded file will temporarily stored on the server at
    $_FILES['file']['tmp_name']

    You need to move it to a folder, or read it into db.
    Last edited by hongbo; Jul 1, 2008 at 19:55. Reason: typo

  6. #6
    Non-Member
    Join Date
    Feb 2008
    Location
    Idaho Falls, Idaho
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its being put into a db. The config file was:

    require_once('takenout...');


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
  •