php file upload issue with cms

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
ankitm

php file upload issue with cms

Post 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
Last edited by ankitm on Mon Jan 14, 2008 11:20 pm, edited 1 time in total.
ankitm

Re: php file upload issue with cms

Post by ankitm »

pls someone help............... >:(
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: php file upload issue with cms

Post 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.
ankitm

Re: php file upload issue with cms

Post 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
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: php file upload issue with cms

Post 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.
Last edited by hexdj on Tue Jan 15, 2008 9:36 am, edited 1 time in total.
ankitm

Re: php file upload issue with cms

Post by ankitm »

thanks for ur quick help............
Post Reply

Return to “Developers Discussion”