I'm trying to make a script that will upload a couple of file depending of the files selected. to run the script I need to pass the name of a company and a product number
I would call the script like this:
example: http://www.mydomain.com/myscript.php?company=mycompany&products=1
this will prompt me to enter a file and upon submition it should upload it to the right folder on the server but I'm having problems where it won't upload the file.
the form will post to it self passing the company, the product and a bool to upload the file.
here is the code:
<?php
/*
This is the list of products. To determine wichones to show we do a binary math
that calculates wich files to show.
$PM -> 1 $HD -> 2 $AM -> 4 $IT -> 8
$SM -> 16 $HR -> 32 $PP -> 64 $RM -> 128
*/
$PM=1;$HD=2;$AM=4;$IT=8;
$SM=16;$HR=32;$PP=64;$RM=128;
/************************ Create directory structure ************************/
$permiss = 0775;
$basedir = "../_downloads/~~";
$dirowner = "eden_clients";
/*** Variables for file uploading ***/
$extlimit = "yes";
$limitedext = array(".zip");
$sizelimit = "no";
$sizebytes = "200000";
$dl = "http://www.eden.com/demos_evals/_clients/_downloads/~~";
$absolute_path = "/home/www/Eden_Main/demos_evals/_clients/_downloads/~~";
$websiteurl = "http://www.eden.com";
$websitename = "Eden Corporation";
/*** Create directory for the user ***/
if ($company && $create==true)
{
print "<br><b>- Creating client directory ".$basedir.$company."</b><br>";
generatedir($basedir.$company, $permiss);
}
/*** Create directory for the products ***/
if(($products > 0 && $products < 256) && $company && $create==true)
{
if(is_dir($basedir.$company))
{
if($products & $PM){
print "<br><b>- Creating directory for the PM</b><br>";
generatedir($basedir.$company."/PM", $permiss);
uploadfile($PMfile,$absolute_path.$company."/PM");
//@copy($PMfile, "$absolute_path$company/$PMfile") or die("unable to copy $PMfile");
}
if($products & $HD){
print "<br><b>- Creating directory for the HD</b><br>";
generatedir($basedir.$company."/HD", $permiss);
uploadfile($HDfile,$absolute_path.$company."/HD");
}
if($products & $AM){
print "<br><b>- Creating directory for the AM</b><br>";
generatedir($basedir.$company."/AM", $permiss);
uploadfile($AMfile,$absolute_path.$company."/AM");
}
if($products & $IT){
print "<br><b>- Creating directory for the IT</b><br>";
generatedir($basedir.$company."/IT", $permiss);
uploadfile($ITfile,$absolute_path.$company."/IT");
}
if($products & $SM){
print "<br><b>- Creating directory for the SM</b><br>";
generatedir($basedir.$company."/SM", $permiss);
uploadfile($SMfile,$absolute_path.$company."/SM");
}
if($products & $HR){
print "<br><b>- Creating directory for the HR</b><br>";
generatedir($basedir.$company."/HR", $permiss);
uploadfile($HRfile,$absolute_path.$company."/HR");
}
if($products & $PP){
print "<br><b>- Creating directory for the PP</b><br>";
generatedir($basedir.$company."/PP", $permiss);
uploadfile($PPfile,$absolute_path.$company."/PP");
}
if($products & $RM){
print "<br><b>- Creating directory for the RM</b><br>";
generatedir($basedir.$company."/RM", $permiss);
uploadfile($RMfile,$absolute_path.$company."/RM");
}
}
else
{
print "<br><b>- Creating Product Directories</b><br>";
failure("Failed");
print " Directory ".$basedir.$company." doesn't exist<br>";
}
}
function success($word)
{
print "<font color=179D4C><b>$word</b></font>";
}
function failure($word)
{
print "<font color=D72323><b>$word</b></font>";
}
function generatedir($path, $mode)
{
if(is_dir($path))
{ failure("Failed");
print " Directory ".$path." allready exist<br>";
return false;
}
else
{ mkdir($path,$mode);
if(is_dir($path))
{ success("Successful");
print " Directory created<br>";
return true;
}
else
{ failure("Failed");
print " Unable to create directory ".$path."<br>";
return false;
}
}
}
function uploadfile($file, $path)
{
if ($file != "")
{
if (file_exists("$path/$file"))
{
failure("Failed");
print " File allready exists.<br>";
return;
}
if (($sizelimit == "yes") && ($file_size > $sizebytes))
{
failure("Failed");
print " File size exeeded.<br>";
return;
}
$ext = strrchr($file,'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext)))
{
failure("Failed");
print " Unsupported file extension.<br>";
return;
}
if (!@copy($file, "$path/$file"))
{
failure("Failed");
print " Unable to copy the file $file to $path/$file <br>";
return;
}
else
{
success("Successful");
print " File uploaded successfully<br>";
return;
}
}
else
{
failure("Failed");
print " No file selected.<br>";
return;
}
}
function generatelink($url)
{
$defurl = ereg_replace ("http://" , "ftp://", $url);
$defurl = ereg_replace (" " , "+", $defurl);
print "<a href=$defurl target=_new>$defurl</a><br>";
}
function display_header($products, $company)
{
echo "<form method=POST action=$PHP_SELF?products=$products&company=$company&create=true enctype=multipart/form-data>
<br>Select the files to be uploaded and click the UPLOAD button.<br><br>";
}
function display_footer()
{
echo "<button name=submit type=submit>UPLOAD</button>
</form>";
}
function display_product($curprod,$curprodfilename)
{
echo "<p>
Select the $curprod file to upload: <br>
<input type=file name=$curprodfilename size=30>
</p>";
}
if(($products > 0 && $products < 256) && $company && $create==false)
{
display_header($products, $company);
if($products & $PM)
display_product("Project Manager","PMfile");
if($products & $HD)
display_product("Help Desk","HDfile");
if($products & $AM)
display_product("Asset Manager","AMfile");
if($products & $IT)
display_product("Issue Tracker","ITfile");
if($products & $SM)
display_product("Sales Manager","SMfile");
if($products & $HR)
display_product("HR Manager","HRfile");
if($products & $PP)
display_product("IT Power Pac","PPfile");
if($products & $RM)
display_product("Requirements Manager","RMfile");
display_footer();
}
?>
I would really appreciate if anyone could help. please respond to my email