Jump to content

[SOLVED] Help with an File Upload IF statement.


bizerk

Recommended Posts

Okay I have an upload script, where you can upload up to 10 files, and when you press SUBMIT they are all copied to a certain directory. I need a way so that if only lets say 2 files are uploaded, than it only uploads THOSE TWO and does not give me and error saying "COPY FUNCTION did not work". I think that one possible way would be to make a if statement where,

if($imagefile == "something")

{ copy (blablabla)

or die ("blabla"

 

I think that may work, if I make an if statement for EVERY SINGLE upload. Here is the code:

 

<!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=ISO-8859-1" />
<title>Joe Upload</title>
</head>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data">
<b><u>LOGIN INFORMATION:</u></b>
<br />Name: <input type="text" name="name" />
<br />
Password: <input type="password" name="password" />
<br />
<br />
<br />
<br />
<br />
<br />
<b><u>Upload a File:</u></b><br />
1.<input type="file" name="imagefile"><br />
2.<input type="file" name="imagefile2"><br />
3.<input type="file" name="imagefile3"><br />
4.<input type="file" name="imagefile4"><br />
5.<input type="file" name="imagefile5"><br />
6.<input type="file" name="imagefile6"><Br />
7.<input type="file" name="imagefile7"><br />
8.<input type="file" name="imagefile8"><br />
9.<input type="file" name="imagefile9"><br />
10.<input type="file" name="imagefile10"><br />
<br>
<input type="submit" name="Submit" value="Submit">
<br /><br /><br />

<?
$lol = rand(1,100);
$Submit= "Submit";
$browser = $REMOTE_ADDR;
$name = $_POST['name'];
$password = $_POST['password'];
if($_POST['Submit']) {
if($name =="joe" and $password =="sefanubz4f")
{
copy ($_FILES['imagefile']['tmp_name'], "files/$lol".$_FILES['imagefile']['name'])
or die ("Error Occured When Uploading Image File 1 to Directory");
//end imagefile
copy ($_FILES['imagefile2']['tmp_name'], "files/$lol".$_FILES['imagefile2']['name'])
or die ("Error Occured When Uploading Image File 2 to Directory");
//end imagefile2
copy ($_FILES['imagefile3']['tmp_name'], "files/$lol".$_FILES['imagefile3']['name'])
or die ("Error Occured When Uploading Image File 3 to Directory");
//end imagefile3
copy ($_FILES['imagefile4']['tmp_name'], "files/$lol".$_FILES['imagefile4']['name'])
or die ("Error Occured When Uploading Image File 4 to Directory");

copy ($_FILES['imagefile5']['tmp_name'], "files/$lol".$_FILES['imagefile5']['name'])
or die ("Error Occured When Uploading Image File 5 to Directory");

copy ($_FILES['imagefile6']['tmp_name'], "files/$lol".$_FILES['imagefile6']['name'])
or die ("Error Occured When Uploading Image File 6 to Directory");

copy ($_FILES['imagefile7']['tmp_name'], "files/$lol".$_FILES['imagefile7']['name'])
or die ("Error Occured When Uploading Image File 7 to Directory");

copy ($_FILES['imagefile8']['tmp_name'], "files/$lol".$_FILES['imagefile8']['name'])
or die ("Error Occured When Uploading Image File 8 to Directory");

copy ($_FILES['imagefile9']['tmp_name'], "files/$lol".$_FILES['imagefile9']['name'])
or die ("Error Occured When Uploading Image File 9 to Directory");

copy ($_FILES['imagefile10']['tmp_name'], "files/$lol".$_FILES['imagefile10']['name'])
or die ("Error Occured When Uploading Image File 10 to Directory");
    echo "<br>"; 
        echo "Image File One Name: ".$_FILES['imagefile']['name']."<br>"; 
        echo "Image File One Size: ".$_FILES['imagefile']['size']."<br>"; 
        echo "Image File One Type: ".$_FILES['imagefile']['type']."<br>"; 
        echo "Image File One has been copied...."; 

echo "<br>"; 
        echo "Image File Two Name: ".$_FILES['imagefile2']['name']."<br>"; 
        echo "Image File Two Size: ".$_FILES['imagefile2']['size']."<br>"; 
        echo "Image File Two Type: ".$_FILES['imagefile2']['type']."<br>"; 
        echo "Image File Two has been copied...."; 

            echo "<br><br>";
            echo "Here you go Joe <3, the file(".$_FILES['imagefile']['name'].") has been copied correctly. You are currently running: $browser <br><br><br><center><img src='http://minusplus.free.fr/rofl.jpg'><br>Click<a href='/files/'> here</a> to view all your files</center><br><br><br><br><br><br>";?> <object width="200" height="100" align="middle">
<param name="movie" value="http://www.swfupload.com/files/59342joeskate.swf">
<embed src="http://www.swfupload.com/files/59342joeskate.swf" width="550" height="400" align="middle">
</embed>
</object> <? 
		}else{
		echo "Wrong Credentials, Please try to Login Again";
		}
		}
?>

</form>
</body>
</html>

 

So Should I make it so EACH IMAGE has this:

 

for($i=1; $i<=10; $i++){

  if(isset($_FILES['imagefile'.$i]['tmp_name'])){

copy ($_FILES['imagefile']['tmp_name'], "files/$lol".$_FILES['imagefile']['name'])

or die ("Error Occured When Uploading Image File 1 to Directory");

  }

}

 

for($i=1; $i<=10; $i++){

  if(isset($_FILES['imagefile2'.$i]['tmp_name'])){

copy ($_FILES['imagefile2']['tmp_name'], "files/$lol".$_FILES['imagefile2']['name'])

or die ("Error Occured When Uploading Image File 2 to Directory");

  }

}

 

or make it so each has a INDIVISUAL IF... I am confused.

Well, I was working on this for teh whole night, and am still confused. I was experimenting and here is what I have so far with the new UPLOAD code:

 

for($i=1; $i<=10; $i++){
   if(isset($_FILES['imagefile'.$i]['tmp_name'])){
copy ($_FILES['imagefile']['tmp_name'], "files/$lol".$_FILES['imagefile']['name'])
or die ("Error Occured When Uploading Image File 1 to Directory");
echo "uploaded file1 correctly";
   }
   if(isset($_FILES['imagefile2'.$i]['tmp_name'])){
copy ($_FILES['imagefile2']['tmp_name'], "files/$lol".$_FILES['imagefile2']['name'])
or die ("Error Occured When Uploading Image File 2 to Directory");
echo "uploaded fil21 correctly";
}
}

 

Now what Happens is it ONLY will upload 'imagefile'. Not imagefile2. It's strange. Should I put the for statement on the image file 2 as well?

somebody help.

SO how would I incorporate that into my script though. I defined the function uploadFiles... and made it so it copies the files, but it only copies the FIRST FILE:

 

function uploadFiles($key)
{
copy ($_FILES['imagefile']['tmp_name'], "files/$lol".$_FILES['imagefile']['name'])
or die ("Error Occured When Uploading Image File 1 to Directory");
echo "succesful";
}
$lol = rand(1,100);
$Submit= "Submit";
$browser = $REMOTE_ADDR;
$name = $_POST['name'];
$password = $_POST['password'];
if($_POST['Submit']) {
if($name =="joe" and $password =="sefanubz4f")
{
foreach ($_FILES as $key=>$file)
		{
		if (!empty($file['name']))
			{
			uploadFiles($key);
			}
}
		}else{

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.