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

    Likes Received:
    Best Answers:
    Trophy Points:
    HTML Form (uploader.htm)
    <title> Simple W.M.P. Uploader</title>
    <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!">
    Code (markup):

    PHP Script (uploader.php)
    <title>Simple W.M.P. Uploader</title>
    <h1>Upload results</h1>
    $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>";
    Code (markup):
    $file_dir = "/path/to/upload/directory"; // upload path

    from wmp.gr
    Dazed_and_confused, Jul 13, 2005 IP