1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Uploading Images

Discussion in 'PHP' started by kc3, Jul 4, 2005.

  1. #1
    I forgot what the code was for uploading files and my php book is not with me. Can someone tell me how to do it? Also, I need to be able to re-name these images.
     
    kc3, Jul 4, 2005 IP
  2. Dazed_and_confused

    Dazed_and_confused Well-Known Member

    Messages:
    2,071
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    120
    #2
    HTML Form (uploader.htm)
    
    <html>
    <head>
    <title> Simple W.M.P. Uploader</title>
    </head>
    <body>
    <form action="uploader.php" enctype="multipart/form-data" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="51200">
    File to Upload: <input type="file" name="fileupload"><br><br>
    <input type="submit" value="upload!">
    </form>
    </body>
    </html>
    Code (markup):

    PHP Script (uploader.php)
    
    <html>
    <head>
    <title>Simple W.M.P. Uploader</title>
    </head>
    <body>
    <h1>Upload results</h1>
    <?php
    $file_dir = "/path/to/upload/directory";
    
    foreach($_FILES as $file_name => $file_array) {
       print "path: ".$file_array['tmp_name']."<br>\n";
       print "name: ".$file_array['name']."<br>\n";
       print "type: ".$file_array['type']."<br>\n";
       print "size: ".$file_array['size']."<br>\n";
    
       if (is_uploaded_file($file_array['tmp_name'])) {
          move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Problem");
           print "Moved ok!<br><br>";
       }
    }
    ?>
    </html>
    Code (markup):
    $file_dir = "/path/to/upload/directory"; // upload path

    from wmp.gr
     
    Dazed_and_confused, Jul 13, 2005 IP