The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> image upload?
xxkasperxx
post Apr 6 2012, 10:55 AM
Post #1


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



How do i create a image uploaing page?
I want the user to be able to select multiple pictures with just one window (ctlr click on pics, or drag for selected ones.)
And then upload them all to the server..

I could only find out how to get 1 picture working..

imageupload.php

CODE
<html>
<head>
<title>HTML Form for uploading image to server</title>
</head>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="file" />

<input type="submit" value="Send" />
</p>
</form>


</body>
</html>


upload_file.php
CODE
<?php


  /*
   foreach ($_FILES['file']['name'] as $i => $name) {
      
        if ($_FILES['file']['error'][$i] == 4) {
            continue;
        }
      
        if ($_FILES['file']['error'][$i] == 0) {
          
             if ($_FILES['file']['size'][$i] > 99439443) {
                $message[] = "$name exceeded file limit.";
                continue;  
             }
                $target_path = getenv("DOCUMENT_ROOT")."/Civic Association/upload/";
echo $target_path;
                $target_path = $target_path .basename( $name);

                if(move_uploaded_file($i, $target_path)) {
                    echo "The file ".  $name.
                    " has been uploaded";
                } else{
                    echo "<br><b>There was an error uploading the file, please try again!</b>";
                }
            echo "<br>";
             $uploaded++;
        }
  
   }
  
   echo $uploaded . ' files uploaded.';
  
   foreach ($message as $error) {
      echo $error;
   }
*/
/*foreach ($_FILES['file'] as $position => $file) {
    // should output array with indices name, type, tmp_name, error, size
    var_dump($file);
*/
    
    
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000000000000000000000000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
xxkasperxx
post Apr 7 2012, 12:01 PM
Post #2


Serious Coder
*****

Group: Members
Posts: 261
Joined: 30-April 11
Member No.: 14,449



I still do not get how to get the array inputs through posting to the php page.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th April 2024 - 05:15 AM