Page 1 of 1

Problem with Upload Code!! Help Plz

Posted: Fri Jul 04, 2003 3:31 am
by stonerifik
i know ive posted a topic similair to this before.. but anyways

Code: Select all

<? 
##############
# VARIABLES
##############
 $uploaddir_trainers = $_SERVER['DOCUMENT_ROOT']."/downloads/trainers/".$_POST['alphabet']."/"; 
 $uploaddir_editors = $_SERVER['DOCUMENT_ROOT']."/downloads/editors/".$_POST['alphabet']."/"; 
 $uploaddir_patches = $_SERVER['DOCUMENT_ROOT']."/downloads/patches/".$_POST['alphabet']."/"; 
 $uploaddir_tutorials = $_SERVER['DOCUMENT_ROOT']."/downloads/tutorials/"; 
 $uploadext1="zip"; 
 $uploadext2="ZIP";
##############
# UPLOAD CODE
##############
 list($filename,$extension) = explode(".",$_FILES[file1][name]); 
 if($extension==$uploadext1 || $extension==$uploadext2) 
 { 
 	if ($_POST['directory'] == "trainers"){
 		if ($_FILES[file1] != "") { 
  			copy($_FILES[file1][tmp_name], $uploaddir_trainers .$_FILES[file1][name]) or die("Couldnt Upload File"); 
  		} 
 		else { 
  			die("no file selected for upload!");
  		}
	}
 	else if ($_POST['directory'] == "editors"){
 		if ($_FILES[file1] != "") { 
  			copy($_FILES[file1][tmp_name], $uploaddir_editors .$_FILES[file1][name]) or die("Couldnt Upload File"); 
  		} 
 		else { 
  			die("no file selected for upload!");
  		}  
	}
 	else if ($_POST['directory'] == "patches"){
 		if ($_FILES[file1] != "") { 
  			copy($_FILES[file1][tmp_name], $uploaddir_patches .$_FILES[file1][name]) or die("Couldnt Upload File"); 
  		} 
 		else { 
  			die("no file selected for upload!");
  		}  
	}
 	else if ($_POST['directory'] == "tutorials"){
 		if ($_FILES[file1] != "") { 
  			copy($_FILES[file1][tmp_name], $uploaddir_tutorials .$_FILES[file1][name]) or die("Couldnt Upload File"); 
  		} 
 		else { 
  			die("no file selected for upload!");
  		}  
	}
 } 
 else { 
  die("wrong extention for upload");
 }





?> 




<HTML> 
<center><h3>Upload was Successfull!</h3></center>
<center><h2><a href=members.php?id=release2>Step 2</a></h2></center>
</HTML>
this code works fine for the server i have running on my own computer.. but when i uploaded it to my site, i get the die("wrong extention for upload") ... it really works wonderfully on my own computer, but i dont know what is wrong when i access it from my site.

i am uploading a .zip file as well, and the file does have size, so no error with that... any one help? please!? thank you

Posted: Fri Jul 04, 2003 6:53 am
by m@ndio
all your directories correctly setup on the server?

Posted: Fri Jul 04, 2003 8:21 am
by pootergeist
you may be getting an undefined index due to not enclosing your $_FILES indices within quotes.
you could also cut that code down hugely and remove the repetitions - for example

Code: Select all

if($_FILES['file1']['error'] == 0)
	{
	// file uploaded and sitting in tmp dir
	if(strtolower(substr($_FILES['file1']['name'],-4)) == '.zip')
		{
		// is a .zip - could perform a ['type'] test as well
		$target_dir = $_SERVER['DOCUMENT_ROOT']. '/downloads/' .$_POST['directory']. (($_POST['directory'] == 'tutorials') ? '' : '/'.$_POST['alphabet']). '/';
		if(!move_uploaded_file($_FILES['file1']['tmp_name'],$target_dir.$_FILES['file1']['name']))
			{
			// move file failed
			echo 'rats - made it to tmp, just could nay move to '.$target_dir.'<br />';
			}
		else
			{
			echo 'yay ' .$_FILES['file1']['name']. ' slung into ' .$target_dir.'<br />';
			}
		}
	else
		{
		echo 'somehow think that was nay a zip file.<br />';
		}
	}
and, as mentioned, make sure the chmod permissions are set on all the receiving folders.

Posted: Fri Jul 04, 2003 2:38 pm
by stonerifik
thanks for the reply's, i tried to understand you cut down code, but my code makes more sense to myself... and hum i got all the directorys on my server, so thats not the problem, and im running a Windows server as well and i dont think u can chmod things on it

and hum ill try adding the quotes to my code and see if that makes a diffrence.. thanks much for the replies

Posted: Fri Jul 04, 2003 2:47 pm
by stonerifik
hmmm adding the quotes still didnt work.. i have no idea what my problem is, the code works fine on my own server :(

Posted: Fri Jul 04, 2003 4:55 pm
by stonerifik
alright, i looked through your code again, and found everything i missed before, and then used it... and again it works fine on my computer... but when uploaded to the site still get the non-zip format error.... help! :P