Page 1 of 1

php file upload issue with cms

Posted: Mon Jan 14, 2008 11:09 pm
by ankitm
i got code in php with upload file from cms form and send to email as attachment the code wht i have is


  ".$file."";
      $filelist .= "    x";
   }
}

function do_upload($upload_dir, $upload_url) {

$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
  $file_name = str_replace("\\","",$file_name);
  $file_name = str_replace("'","",$file_name);
$file_type = $_FILES['userfile']['type'];
$file_size = $_FILES['userfile']['size'];
$result    = $_FILES['userfile']['error'];
$file_url  = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;

//File Name Check
    if ( $file_name =="") {
    $message = "Invalid File Name Specified";
    return $message;
    }
    //File Size Check
    else if ( $file_size > 2000000) {
    // print $file_size;
    //    $message = "The file size is over 1MB.";
    //    return $message;
    }
    //File Type Check  -- Prevent possible attacks
    else if ( strpos($file_name,".php") !== false
           || strpos($file_name,".cgi") !== false
           || strpos($file_name,".htm") !== false
           || strpos($file_name,".phtm") !== false )
      return;
    else if ( strpos($file_type,"image") !== false
      || $file_type == "application/msword");
    else {
        //$message = "Sorry, demo. only allows image or ms-word upload." ;
        //$message .= "You may allow other types(i.e, .zip) on your own server." ;
        //return $message;
    }

    $result  =  move_uploaded_file($temp_name, $file_path);
    if (!chmod($file_path,0755))
      $message = "change permission to 755 failed.";
    else
  $msgban = ($result)?"$file_name" :
      $message = ($result)?"$file_name uploaded successfully. In cel mult 24 ore Bannerul va aparea pe site." :
              "Somthing is wrong with uploading a file.";

    return $message;
}

?>




\r\n";
$headers .= "Reply-To: " . $_POST["email"];



$content = "Name             : " . $_POST["name"] . "\n";
$content .= "Email Address    : " . $_POST["email"] . "\n";
$content .= "Comments         : " . $_POST["website"] . "\n";
$content .= "Comments         : " . $_POST["website"] . "\n";


mail($sendTo, $subject, $content, $headers);


?>




the code works fine with standalone form but when used from cmsmadesimple it doesnot can someone pls help me find wht i m doing wrong right now i m not bothered abt attachment but prblem is the file is not getting uploaded on server

Re: php file upload issue with cms

Posted: Mon Jan 14, 2008 11:20 pm
by ankitm
pls someone help............... >:(

Re: php file upload issue with cms

Posted: Tue Jan 15, 2008 8:31 am
by hexdj
Have you tried the Uploads module instead? it lets frontend users upload files themselves. Also check out Form Builder if you wanna send email, these are both pretty neat modules, very useful and you don't have to re-invent the wheel.

Re: php file upload issue with cms

Posted: Tue Jan 15, 2008 9:27 am
by ankitm
thanks a lot of information i just installed the upload module and cmsmailer now trying to figure out way to use them in my custom form if u can help with tht........thanks

Re: php file upload issue with cms

Posted: Tue Jan 15, 2008 9:33 am
by hexdj

Code: Select all

{cms_module module='FormBuilder' form='contact'}
If you installed FormBuilder the above code will output a contact form, which you can modify from the Module's interface. Actually FormBuilder also lets you upload files and have them sent as attachments, please read the Module's help and don't post multiple threads for the same question.

Re: php file upload issue with cms

Posted: Tue Jan 15, 2008 9:41 am
by ankitm
thanks for ur quick help............