Jump to content

multiple file upload


awiedman

Recommended Posts

You can't upload multiple files at the same time, unless you use something like jQuery or Prototype. We're not going to supply you with code either, at least attempt to make it then post the code that isn't working here and we'll take a look. Remember to tell us why it isn't working.

 

To start, have a look at the manual. It has some examples.

Link to comment
https://forums.phpfreaks.com/topic/129021-multiple-file-upload/#findComment-668858
Share on other sites

So far this is what I have, but I can't figure out how to make it for it restricts certain format/filetypes and to make it multi upload.

 

 

Index.html

<html>
<head>
<title>Upload Media</title>
</head>
<body>
<center>
<table cellspacing="0" border="1" bordercolor="black">
<tr><td background="http://rphosting.net/dir_images/tableheader.png" colspan="2"><center><font color="white">Upload Media</font></td>
</tr>
<tr>
<td><form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="120000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form></td>

 

Uploader.php

 
<center>
<table cellspacing="0" border="1" bordercolor="black">
<tr><td background="http://rphosting.net/dir_images/tableheader.png" colspan="2"><center><font color="white">Upload Media</font></td></tr>
<tr>
<td>
<?php
$target_path = "/home/rphost/public_html/upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>
</td>
</tr>
<tr>
<td>
<br>
<small>File Name:</small><br>
<?php echo "<input type='text' size='25' onclick='javascript&#058;select();' value='".  basename( $_FILES['uploadedfile']['name']). 
    "'>";?>
<br>
Preview:<br>
<?php echo "<img src='http://rphosting.net/uploads/".  basename( $_FILES['uploadedfile']['name']). 
    "'>";?></td>
</tr>
<tr>
<td><center><form action="index.php" method="post"><input type="submit" value="Return to Upload Page"></center></td>
</tr>
</table>

 

Uploads folder must have file permissions of 777

 

But i also found this code at: http://www.w3schools.com/php/php_file_upload.asp

It's supposed to put restricions on it but I can't figure out how to apply it to my upload script

 

<?php

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/129021-multiple-file-upload/#findComment-668890
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.