PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?
##############
# 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
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
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.
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
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!