Jump to content

multi uplad form


lucan

Recommended Posts

Can some one tell me how to convert this code to deal with multiple uploads into different folders. thanks in advance.

 

<form action="upload.php" method="post" enctype="multipart/form-data">  
               <label>First Name</label><input type="text" name="fname" /><br />   
               <label>Last Name</label><input type="text" name="lname" /><br />        
               One  <label>Upload Image</label> <input type="file" name="image" /><br>
               Two  <label>Spec</label> <input type="file" name="spec" /><br />
                       <input type="hidden" name="MAX_FILE_SIZE" value="100000" />  
                       <input type="submit" id="submit" value="Upload" />  
</form>  

 

 

<?php
function is_valid_type($file)  
{     
     $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif");  
     if (in_array($file['type'], $valid_types))  
         return 1;  
     return 0;  
}  
function showContents($array)  
{  
     echo "<pre>";  
     print_r($array);  
     echo "</pre>";  
}  
$TARGET_PATH = "images/";  

$fname = $_POST['fname'];  
$lname = $_POST['lname'];  
$image = $_FILES['image'];

$fname = mysql_real_escape_string($fname);  
$lname = mysql_real_escape_string($lname);  
$image['name'] = mysql_real_escape_string($image['name']); 

$TARGET_PATH .= $image['name'];  

if ( $fname == "" || $lname == "" || $image['name'] == "" )  
{  
     $_SESSION['error'] = "All fields are required";  
     header("Location: index.php");  
     exit;  
}  
if (!is_valid_type($image))  
{  
     $_SESSION['error'] = "You must upload a jpeg, gif, or bmp";  
     header("Location: index.php");  
     exit;  
}  
if (file_exists($TARGET_PATH))  
{  
     $_SESSION['error'] = "A file with that name already exists";  
    header("Location: index.php");  
     exit;  
}   
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))  
{  
     $sql = "insert into people (fname, lname, filename,spec) values ('$fname', '$lname', '" . $image['name'] ."')";  
     $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());  
     header("Location: images.php");  
     exit;  
}  
else 
{     
     $_SESSION['error'] = "Could not upload file.  Check read/write persmissions on the directory";  
     header("Location: index.php");  
     exit;  
}  

?>

Link to comment
https://forums.phpfreaks.com/topic/228513-multi-uplad-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.