Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 12, 2013, 10:43 AM   #1
nomade
macrumors member
 
Join Date: Dec 2006
Help needed for debugging a mailing with attachmeny in PHP

I have use a very close version of this script in many web site but this one doesn't work. It's a mailing list with file attached.

Code:
// I drop the file on the server 
if(!empty($_FILES['fichier'])){
$nom = substr($_FILES['fichier']['name'], strripos($_FILES['fichier']['name'], '.'));
$extension= substr($nom, 1, 3);
$connection = ftp_connect('cld-charlevoix.org') or die("connection impossible");
ftp_login($connection, $user, $password) or die("user erreur ou mot de passe");
ftp_put($connection,("/public_html/admin/attachement/".$_FILES['fichier']['name']),$fichier,FTP_BINARY) or die("le transfert marche pas");
ftp_close($connection);
echo "go";
}

// then i create the script for the mailing
if(isset($_POST['groupe'])){
//---------------------------------------------------------- ramasse le texte et le titre
$sql_texte2=mysql_query("SELECT * FROM texte WHERE id_texte='18'");
$ligne_texte2=mysql_fetch_array($sql_texte2);
$titre_texte2=$ligne_texte2['titre']; // le titre du message

//------------------------------------------
foreach($_POST['groupe'] as $lesgroupes) {
if($_POST['groupe'][0] !='tous'){ 
$sql_listeenvoi=mysql_query("SELECT * FROM listeenvoi where groupe='".$lesgroupes."' and actif='oui' ORDER BY courriel ASC");
 }
else{
$sql_listeenvoi=mysql_query("SELECT * FROM listeenvoi where actif='oui' ORDER BY courriel ASC");
}
$i=1;

while($ligne_listeenvoi=mysql_fetch_array($sql_listeenvoi)){
$to = "".$ligne_listeenvoi['courriel']."";

//------------------------------------------
$sujet = $titre_texte2; 
$delimiteur=md5(uniqid(rand()));
$entete = "MIME-version: 1.0\n"; 
$entete  .= "From:info@cld-charlevoix.org\n"; 
$entete .= "Content-type: multipart/mixed; boundary=".$delimiteur." \n ";
$entete .= " \n";
$sujet = $titre_texte; 
$message ="--".$delimiteur."\n";
$message .= "Content-type: text/html; charset= \"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding:8bit\n";
$message .= "\n";
$message .="Hello";

$message .= "\n";
$message .="--".$delimiteur." \n";
if(!empty($_FILES['fichier']['name'])){
$fichier ="attachement/".$_FILES['fichier']['name']."";
$attache = file_get_contents($fichier);
$attache = chunk_split(base64_encode($attache));
$message .="--".$delimiteur." \n";
$message .="Content-Type: application/".$extension."; name=".$fichier." \n";
$message .="Content-Transfer-Encoding: Base64\n";
$message .="Content-Disposition: inline; filename=".$fichier." \n";
$message .= "\n";
$message .= $attache." \n";
$message .= "\n";

$message .="--".$delimiteur." \n";
}
mail($to,$sujet,$message,$entete, "-flamuse@lamuse.com");
}}}
echo "$to<br>";
?>
The file is indeed on the server but the image/file is not interpreted correctly.
Any suggestion will be welcomed
nomade is offline   0 Reply With Quote
Old Feb 12, 2013, 12:02 PM   #2
SrWebDeveloper
macrumors 68000
 
SrWebDeveloper's Avatar
 
Join Date: Dec 2007
Location: Alexandria, VA, USA
 
Not a clue what you mean by "not interpreted" so if this advice does not help you need to explain exactly what you mean and what happened when you run the script.

In PHP uploaded files are stored in a temporary location and must be copied to a real folder to attach or FTP, whatever.

I don't see something similar in concept to this, which moves the uploaded temp file to a REAL folder with the proper name in this example called upload. Edit to suit your own needs:

PHP Code:
      move_uploaded_file($_FILES["file"]["tmp_name"],
      
"upload/" $_FILES["file"]["name"]);
      echo 
"Stored in: " "upload/" $_FILES["file"]["name"]; 
__________________
Jim Goldbloom
Sr. Web Developer, owner GoldTechPro, LLC
http://www.GoldTechPro.com
SrWebDeveloper is offline   0 Reply With Quote
Old Feb 12, 2013, 12:19 PM   #3
nomade
Thread Starter
macrumors member
 
Join Date: Dec 2006
Quote:
Originally Posted by SrWebDeveloper View Post
Not a clue what you mean by "not interpreted" so if this advice does not help you need to explain exactly what you mean and what happened when you run the script.

In PHP uploaded files are stored in a temporary location and must be copied to a real folder to attach or FTP, whatever.

I don't see something similar in concept to this, which moves the uploaded temp file to a REAL folder with the proper name in this example called upload. Edit to suit your own needs:

Oh sorry for the bad explanation, when I said not interpreted I mean the image attached is show in the email as caracters within boundary but not as an image.

The file is already upload to the server :
Code:
if(!empty($_FILES['fichier'])){
$nom = substr($_FILES['fichier']['name'], strripos($_FILES['fichier']['name'], '.'));
$extension= substr($nom, 1, 3);
$connection = ftp_connect('cld-charlevoix.org') or die("connection impossible");
ftp_login($connection, $user, $password) or die("user erreur ou mot de passe");
ftp_put($connection,("/public_html/admin/attachement/".$_FILES['fichier']['name']),$fichier,FTP_BINARY) or die("le transfert marche pas");
ftp_close($connection);
echo "go";
}
Thanks for your help
nomade is offline   0 Reply With Quote
Old Feb 12, 2013, 12:45 PM   #4
SrWebDeveloper
macrumors 68000
 
SrWebDeveloper's Avatar
 
Join Date: Dec 2007
Location: Alexandria, VA, USA
 
The actual file is stored in $_FILES["file"]["tmp_name"] and you must move it as in my example code. Then you can FTP or attach via email, etc. I already told you I don't see the move command anywhere in your code.

Did you login to the FTP server and not only confirm the file name is there but that it's the actual image? Download it manually to be sure. To me looks like you're uploading a file name, not a binary. And in your email code, no move command so binary and it would end up the way you see it now.

Anyone else following this please correct me if I'm wrong on this or missing something obvious!
__________________
Jim Goldbloom
Sr. Web Developer, owner GoldTechPro, LLC
http://www.GoldTechPro.com
SrWebDeveloper is offline   0 Reply With Quote
Old Feb 12, 2013, 12:52 PM   #5
nomade
Thread Starter
macrumors member
 
Join Date: Dec 2006
Quote:
Originally Posted by SrWebDeveloper View Post
The actual file is stored in $_FILES["file"]["tmp_name"] and you must move it as in my example code. Then you can FTP or attach via email, etc. I already told you I don't see the move command anywhere in your code.

Did you login to the FTP server and not only confirm the file name is there but that it's the actual image? Download it manually to be sure. To me looks like you're uploading a file name, not a binary. And in your email code, no move command so binary and it would end up the way you see it now.

Anyone else following this please correct me if I'm wrong on this or missing something obvious!
The file is move to physical folder here:
Code:
ftp_put($connection,("/public_html/admin/attachement/".$_FILES['fichier']['name']
I do log in ftp here :
Code:
$connection = ftp_connect('cld-charlevoix.org') or die("connection impossible");
ftp_login($connection, $user, $password) or die("user erreur ou mot de passe");
yes i did check the image on the server and it's in fact an image.

Nomade
nomade is offline   0 Reply With Quote
Old Feb 12, 2013, 01:19 PM   #6
SrWebDeveloper
macrumors 68000
 
SrWebDeveloper's Avatar
 
Join Date: Dec 2007
Location: Alexandria, VA, USA
 
I mean this respectfully, but the code you posted is how to ftp a file in PHP but you must have some other code you'r not telling us about that places the file in the source server path specified PRIOR to FTP based on your code as posted here.

Look at this example written by someone else on php.net which I am copying to show you they're using the 'tmp_name' key of the $_FILES array to create the variable that stores the actual file:

PHP Code:
EXAMPLE:

When sending files using a form and PHP, make sure that all the data (text files etc...) are retreived with $_POST, and files (smiley.png, compression.zip, etc...) are retreived with $_FILES.

here's what your start of a results.php file might look like:
<?PHP
   $myName 
$_POST['name']; //This will copy the text into a variable
   
$myFile $_FILES['file_name']; // This will make an array out of the file information that was stored.
?>

Now when it comes to transmitting that information...

<?PHP
        $destination_path 
"src/bin/"

//where you want to throw the file on the webserver (relative to your login dir)

    
$destination_file $destination_path."img.jpg";

//This will create a full path with the file on the end for you to  use, I like splitting the variables like this in case I need to use on on their own or if I'm dynamically creating new folders.

        
$file $myFile['tmp_name'];

//Converts the array into a new string containing the path name on the server where your file is.

    
$upload ftp_put($conn_id$destination_file$fileFTP_BINARY);// upload the file
    
if (!$upload) {// check upload status
        
echo "FTP upload of $destination_file has failed!";
    } else {
        echo 
"Uploaded $file to $conn_id as $destination_file";
    }
?>
As to email, similar situation, but I already gave you example code for that.

I want to be clear on this -- $_FILES['file_name'] does not store the actual file when processing server side immediately after an upload. $_FILES['tmp_name'] does and is physically stored in the temp path on your server unless you move it, otherwise when the PHP script ends it is removed from the server.

I'll leave it to others to jump in, I've done all I can do on this one.
__________________
Jim Goldbloom
Sr. Web Developer, owner GoldTechPro, LLC
http://www.GoldTechPro.com
SrWebDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
[php] - php problems os x mountain lion 10.8.2 cakas6933 OS X 10.8 Mountain Lion 4 Jun 10, 2014 09:08 AM
Xcode 4.6 debugging thrill4rishabh Mac Programming 10 Nov 28, 2013 05:59 PM
Debugging Daemons mehdies Mac Programming 5 Jun 20, 2013 03:46 AM
Debugging - When you were new to programming Tander iPhone/iPad Programming 33 Jun 11, 2013 05:22 PM
Debugging in TexShop A..J Mac Applications and Mac App Store 0 Dec 17, 2012 10:34 AM

Forum Jump

All times are GMT -5. The time now is 12:24 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC