0

i try to puth the files path in a mail for download it without ftp

$nomecognome    = $_POST['cname'];
$email          = $_POST['cemail'];
$biography      = $_POST['ctext'];
$datanascita    = $_POST['cdata'];
$controllo      = $_POST['ccontrol'];
$files          = $_FILES['uploader'];

if(empty($controllo)){

i clear the name

$accenti = array( 'à' , 'è' , 'é' , 'ì' , 'ò' , 'ù' , '\'' , ' ' );
$noaccenti = array( 'a' , 'e' , 'e' , 'i' , 'o' , 'u' , '_' , '_' );
$author = strtolower( str_replace( $accenti , $noaccenti , $nomecognome ) );

create an array for future comparison file ext

$allowedExtensions = array('jpg', 'jpeg', 'png', 'bmp', 'tiff', 'gif', 'pdf');

control if the form is empty

if ( !empty ( $files ) ){

start uploading images

    foreach ($files['name'] as $key => $value) {

        if(is_uploaded_file($files['tmp_name'][$key]) && $files['error'][$key] == 0) {

Create an unique name for the file using the name of user and random number plus filename

            $filename = $files['name'][$key];
            $filename = $author.rand(0,99).$filename;
            //array_push($path, 'http://www.magic-promo.it/uploads/'.$author.$value);

Check if the file was moved

            if( move_uploaded_file( $files['tmp_name'][$key], 'uploads/'. $filename) ) {

here i want to create the array ith each image path to send mail

                foreach ($filename as $filenames) {
                    $pathfile[] = array($filename);
                }

                $body = implode(',', $pathfile);
                echo $body; //to view the list of path
            }
            else{
                echo move_uploaded_file($files['tmp_name'][$key], 'uploads/'. $filename);
                echo 'file non uploadato';
            }
        }
        else {
            echo 'The file was not uploaded.';
        }

    }

i thanks for the help!

5
  • 1
    I'm pretty sure foreach ($filename as $filename) { is not a valid PHP syntax. Change the second $filename to a different variable. Commented Aug 10, 2013 at 14:33
  • yes, true, but doesn't work. Thanks for the advice Commented Aug 10, 2013 at 14:36
  • It was just a comment, not an answer. :) Commented Aug 10, 2013 at 14:37
  • 3
    what is the question? what is the error? Commented Aug 10, 2013 at 14:42
  • the question is how can i include in a mail all path file uploaded, the error is if i use a foreach loop it's create various array with one data Commented Aug 10, 2013 at 14:53

1 Answer 1

0

Try this:

$pathfile = array(); // prevent undefined variable notice
if ( !empty ( $files ) ) {
    foreach ($files['name'] as $key => $value) {
        if(is_uploaded_file($files['tmp_name'][$key]) && $files['error'][$key] == 0) {

            // Create an unique name for the file using the name of user and random number plus filename
            $filename = $files['name'][$key];
            $filename = $author.rand(0,99).$filename;
            //array_push($path, 'http://www.magic-promo.it/uploads/'.$author.$value);

            //Check if the file was moved
            if( move_uploaded_file( $files['tmp_name'][$key], 'uploads/'. $filename) ) {
                $pathfile[] = $filename;                
            } else {
                echo move_uploaded_file($files['tmp_name'][$key], 'uploads/'. $filename);
                echo 'file non uploadato';
            }
        } else {
            echo 'The file was not uploaded.';
        }
    }
}
$body = implode(',', $pathfile);        // $body = implode("\n", $pathfile);
echo $body; //to view the list of path
2
  • if i print filename i don't retrieve nothing. if i don't use in array how can i put all the path in the mail. if i don't use array it send a mail for every file Commented Aug 10, 2013 at 15:06
  • I understood what you mean. Check edited answer. Hope this helps :) Commented Aug 10, 2013 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.