Jump to content

Multiple Image Upload Help


richiejones24

Recommended Posts

I am trying to write a script to handle multiple image uploads however i cant get it to work i am a total novice in php so please be kind in your replys :-)

 

<?php

 

$allowed_filetypes = array('.jpg','.gif','.bmp','.png','.JPG','.PNG','.BMP','.GIF'); //These will be the types of file that will pass the validation.

$upload_path = '../pic_upload/'; // The place the files will be uploaded to.

 

foreach ($_FILES["pictures"]["error"] as $key => $error)

{

$filename = $_FILES['pictures']['name'][$key];

$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

 

if(!empty($filename))        //is it empty

{

if ($_FILES["pictures"]["size"][$key] >= 9000000)

die ('Sorry the picture is too Big!');

}

 

if(!empty($filename))        //Is it empty

{

if(!in_array($ext,$allowed_filetypes))                                          //Is the file Allowed

      die('The file you attempted to upload is not allowed! Pictures only!.');

}

 

if ($error == UPLOAD_ERR_OK) {

        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];

        $name = $_FILES["pictures"]["name"][$key];

        move_uploaded_file($tmp_name, "$upload_path/$ran$name");

 

if (!$i++) print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">

<html xmlns=\"http://www.w3.org/1999/xhtml\">

<head>

<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />

<title>Untitled Document</title>

</head>

 

<body>

<div align=\"center\"><img src=\".../image/8-1.gif\" width=\"100\" height=\"100\" /></div>

<form id=\"form1\" name=\"form1\" method=\"get\" action=\"reg.php\">

<div align=\"center\">

        <input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" />

        <input type=\"hidden\" name=\"reg\" value=\"6\">

  <p>\n";

 

print "<input type=\"hidden\" name=\"pic$key\" value=\"$ran$name\">\n";

 

 

if (!$i++) print "</p>

  <p>

    <label>

      </div>

    </label>

  </p>

</form>

<p> </p>

</body>

</html>\n";

 

} }

?> 

[code=php:0]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.