The full file system is the way the folders are structured in the site ?

It the directory structure of your webspace on the server. Create a file with this, put it in your main directory and open it:

<?php
  echo $_SERVER['DOCUMENT_ROOT'];
?>

That will give the full file system path to your main directory.


Matti Ressler
Suomedia

Could you please give me a detailed explanation and example about what you said the path must be writeable 777. Beatre i'm kind of lost when you mention that ?

On some web servers you can set permissions using your FTP client. In most you can right click the file or directory and chosse to set permissions. I use Filezilla and it has "file attributes" in the right click menu.

Alternatively, in your web hosting control panel you should have a file manager. Please consult the documentation for your hosting on how to set file and directory permissions.

If you are on a Windows server, I know absolutely nothing :icon_cheesygrin:


Matti Ressler
Suomedia

Is it possible to change the path of the attachment script to an email address so it is also sent to the same place as the rest of the text ?

The image(s) must be attached to the mail in the way that I showed you. Exactly where on the server the file is moved to is up to you. It actually is normally uploaded to /tmp/ and must be moved from there to a directory within your webspace. This is done with move_uploaded_file() that you see in my script.

If you are attaching mutiple images, you can use a loop rather than repeating the same code multiple times.


Matti Ressler
Suomedia

Okay..... So if i create a folder called upload in the server and in the path put uploader will the attached files be sent to this folder ?

Yes. This should work:

$path = $_SERVER['DOCUMENT_ROOT'] . '/upload/';

Matti Ressler
Suomedia

hope this wil help u .if not reply me
the path should be something like /home/wc.php

mail_attachment.php

<?php
function mail_attachment ($from , $to, $subject, $message, $attachment){


    $fileatt = $attachment; // Path to the file                  
    $fileatt_type = "application/octet-stream"; // File Type 
    $start=    strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
    $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the     attachment 

    $email_from = $from; // Who the email is from 
    $email_subject =  $subject; // The Subject of the email 
    $email_txt = $message; // Message that the email has in it 
    
    $email_to = $to; // Who the email is to

    $headers = "From: ".$email_from;

    $file = fopen($fileatt,'rb'); 
    $data = fread($file,filesize($fileatt)); 
    fclose($file); 
    $msg_txt="\n\n";

    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    
    $headers .= "\nMIME-Version: 1.0\n" . 
            "Content-Type: multipart/mixed;\n" . 
            " boundary=\"{$mime_boundary}\""; 

    $email_txt .= $msg_txt;
    
    $email_message .= "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
               "Content-Transfer-Encoding: 7bit\n\n" . 
    $email_txt . "\n\n"; 

    $data = chunk_split(base64_encode($data)); 

    $email_message .= "--{$mime_boundary}\n" . 
                  "Content-Type: {$fileatt_type};\n" . 
                  " name=\"{$fileatt_name}\"\n" . 
                  //"Content-Disposition: attachment;\n" . 
                  //" filename=\"{$fileatt_name}\"\n" . 
                  "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                  "--{$mime_boundary}--\n"; 


    $ok = @mail($email_to, $email_subject, $email_message, $headers); 

    if($ok) { 
    } else { 
        die("Sorry but the email could not be sent. Please go back and try again!"); 
    } 
}
?>

where u want to add mail code

<?
session_start();
include "mail_attachment.php";
 ?>
$sent1 = mail_attachment("cgbasket@careerglitters.com",$too, $subject1, $body1, $attachment);

i have attached my php script that i need to attach files to. Could you please place that attachment script you gave me queec?

sorry i mean queenc

Hi suomedia

I used the script that you said i should place on the path so the files are sent to server but it gives a error saying unexpected T_CONSTANT_ENCAPSED_STRING IN the php file...... What could be the problem now ?

<?
include "mail_attachment.php";
 ?>
$sent1 = mail_attachment("cgbasket@website.com",$too, $subject1, $body1, $attachment);

u have to include the above code in the file,juct upload the mail_attachment.
u path name should always be as /home/wesite/......start with home then the location of the file

Queenc..... Could you please insert examples on the script to show it should look when its completed because i'm not sure what to place where.... Like the uploaders form name i don't know where it goes, the path should it be to the server and so on...... I would be truly greatful if you could place examples on it

Hi there suomedia

I have been using your attachment script you gave but i have not been successful to this point. I have tried changing the path in ways including using the example you gave me but still no success....... Please help

Mr. suomedia,
I am using windows with WAMP with includes the follwing:
1. PHP 5 ...
2. MySQL ...
3. Apache2 ...

I myself interested in this issue, so I decided to know this problem too, so I did everything what you mentioned in the previous posts, and I don't see any error too. BUT the page 'SignUpFailure.html' contents.

I shall be glad if you shall have a view of the attachment ...

NOTE:
Should be mention, that I am using everything locally on my own computer, it means that I configured a 'mail server', and I can send and receive emails through PHP mail function...

<?
include "mail_attachment.php";
 ?>
$sent1 = mail_attachment("cgbasket@website.com",$too, $subject1, $body1, $attachment);

u have to include the above code in the file,juct upload the mail_attachment.
u path name should always be as /home/wesite/......start with home then the location of the file

Mr. queenc queenc,
I am using Windows with WAMP server ..., and I used the code you posted, I can receive the mail, also I have the attachment in my mail box, but I can not open it.
Also I see the Sorry ... PROMPT after sending the mail ...

Could you please see what is wrong ???

I think the only problem that you have is that you have not respected the case sensitivity of variables, eg, in your form you have the file field named as "Picture" whereas in the processing script it is "picture", eg. $_FILES

The two are NOT the same and for this reason it will never work as it is.


Matti Ressler
Suomedia

Thanks for replying,
I changes it to lower case, and again the same problem, mentioned in above.
could u plz test it once ???
Thanks

Is there an alternative php script that i can use to send files with using form ...... Somebody can you please help me !?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.