Krijg iedere keer de "Failed to move file to /tmp/3ed3186da55a7462dffaeaec5f1449ac0227e16500mHVo "

Ik Neem aan dat me directory niet goed is waar ik het bestand tijdelijke wil opslaan.
Maar het is toch een temp file ?

Alvast bedankt voor de hulp.

Dit zijn de codes standaard PHPmailer scripts.


PHPMailerAutoload.php

<?php
/**
 * PHPMailer SPL autoloader.
 * PHP Version 5
 * @package PHPMailer
 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
 * @author Marcus Bointon (Synchro/coolbru) <[email protected]>
 * @author Jim Jagielski (jimjag) <[email protected]>
 * @author Andy Prevost (codeworxtech) <[email protected]>
 * @author Brent R. Matzelle (original founder)
 * @copyright 2012 - 2014 Marcus Bointon
 * @copyright 2010 - 2012 Jim Jagielski
 * @copyright 2004 - 2009 Andy Prevost
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 * @note This program is distributed in the hope that it will be useful - WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * PHPMailer SPL autoloader.
 * @param string $classname The name of the class to load
 */
function PHPMailerAutoload($classname)
{
    //Can't use __DIR__ as it's only in PHP 5.3+
    $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
    if (is_readable($filename)) {
        require $filename;
    }
}

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
    //SPL autoloading was introduced in PHP 5.1.2
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        spl_autoload_register('PHPMailerAutoload', true, true);
    } else {
        spl_autoload_register('PHPMailerAutoload');
    }
} else {
    /**
     * Fall back to traditional autoload for old PHP versions
     * @param string $classname The name of the class to load
     */
    function __autoload($classname)
    {
        PHPMailerAutoload($classname);
    }
}

?>

En me mailpagina.
<?php
/**
 * PHPMailer simple file upload and send example
 */
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
    // First handle the upload
    // Don't trust provided filename - same goes for MIME types
    // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
    $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        // Upload handled successfully
        // Now create a message
        // This should be somewhere in your include_path
        require 'PHPMailerAutoload.php';
        $mail = new PHPMailer;
        $mail->setFrom('[email protected]', 'First Last');
        $mail->addAddress('[email protected]', 'John Doe');
        $mail->Subject = 'Verkoopmelding'.$Verkoopbureau;
        $mail->msgHTML("My message body");
        // Attach the uploaded file
        $mail->addAttachment($uploadfile, 'My uploaded file');
        if (!$mail->send()) {
            $msg = "Mailer Error: " . $mail->ErrorInfo;
        } else {
            $msg = "Message sent!";
        }
    } else {
        $msg = 'Failed to move file to ' . $uploadfile;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>PHPMailer Upload</title>
</head>
<body>
<?php if (empty($msg)) { ?>
    <form method="post"  enctype="multipart/form-data">
        <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> Send this file: <input name="userfile" type="file">
        <input type="submit" value="Send File">
    </form>
<?php } else {
    echo $msg;
} ?>
</body>
</html>


[size=xsmall]Toevoeging op 29/12/2014 07:52:53:[/size]

p.s wat zijn de code Tags om html in vensters te weergeven op dit form ?

Probeer eens met $_SERVER['DOCUMENT_ROOT'] erbij?


[code]
<form method="post" enctype="multipart/form-data">
Kies een bestand: <input name="userfile" type="file"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="submit" value="Sturen!">
</form>
<?php
if($_SERVER['REQUEST_METHOD']=="POST") {
$uploadfile = $_SERVER['DOCUMENT_ROOT']."contracten/".$_FILES['userfile']['name'];
echo "Upload locatie:".$uploadfile;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$msg = "Gelukt!";
} else {
$msg = 'Failed to move file to ' . $uploadfile;
}
echo $msg;
}
?>

Dit werkt prima bij mij. Daarna kan je PHPmailer weer inbouwen.
Dan is het path niet goed of de rechten zijn niet goed.
Staat de map contracten in dezelfde map als het php-bestand?
Allemaal maar met Aar script krijg ik dit

Upload locatie:/home/reclam2q/public_htmlcontracten/Verkoopfactuur1.pdf
Failed to move file to /home/reclam2q/public_htmlcontracten/Verkoopfactuur1.pdf

Mist een / tussen public_html en contracten volgens mj ?

[size=xsmall]Toevoeging op 30/12/2014 14:18:36:[/size]

Maar dat was niet het probleem nogmaals bedankt voor jullie geduld en hulp
Klopt, dus die zet je er even bij.

$uploadfile = $_SERVER['DOCUMENT_ROOT']."/contracten/".$_FILES['userfile']['name'];

[size=xsmall]Toevoeging op 30/12/2014 14:20:21:[/size]

Werkt het nou opeens?
Wat heb je aangepast?
Ik heb er een map tussen gezet en nu wekt hij wel maar waarom snap ik echt niet ?

Upload locatie:/home/reclam2q/public_html/data/contracten/Verkoopfactuur1.pdf
Ik heb het op Windows uitgetest, blijkbaar zet die er een trailing slash achter.
Blijft nog steeds de vraag: Waarom zou hij falen.

Kan je eens heel de array van $_FILES laten zien?

<?php
echo "<pre>".$_FILES."</pre>";
?>


[size=xsmall]Toevoeging op 30/12/2014 14:23:10:[/size]

Jordy R op 30/12/2014 14:20:55

Ik heb er een map tussen gezet en nu wekt hij wel maar waarom snap ik echt niet ?

Geen rechten om de webroot te schrijven om magische redenen?

Geeft array als waarde
Aar bedoelt dit waarschijnlijk:
<?php
echo "<pre>".print_r($_FILES, true)."</pre>";
?>
Geeft voor versturen Array () en na versturen niks

Upload werkt maar mail script weer niet "Doe ik nu zulke rare dingen"

Hier nogmaals me script tot nu toe

<?php
/**
 * PHPMailer simple file upload and send example
 */
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
    // First handle the upload
    // Don't trust provided filename - same goes for MIME types
    // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
 $uploadfile = $_SERVER['DOCUMENT_ROOT']."/Data/contracten/".$_FILES['userfile']['name'];    
     echo "Upload locatie:".$uploadfile;
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        // Upload handled successfully
        // Now create a message
        // This should be somewhere in your include_path
        require ($_SERVER['DOCUMENT_ROOT'].'/Data/PHPMailerAutoload.php');
        $mail = new PHPMailer;
        $mail->setFrom('[email protected]', 'First Last');
        $mail->addAddress('[email protected]', 'John Doe');
        $mail->Subject = 'Verkoopmelding'.$Verkoopbureau;
        $mail->msgHTML("My message body");
        // Attach the uploaded file
        $mail->addAttachment($uploadfile, 'My uploaded file');
        if (!$mail->send()) {
            $msg = "Mailer Error: " . $mail->ErrorInfo;
        } else {
            $msg = "Message sent!";
        }
    } else {
        $msg = 'Failed to move file to ' . $uploadfile;
    }
}

echo "<pre>".print_r($_FILES, true)."</pre>";

?> 
<!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8"/>
 <title>PHPMailer Upload</title>
 </head>
 <body>
 <?php if (empty($msg)) { ?> 
 <form method="post" enctype="multipart/form-data">
 <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> Send this file: <input name="userfile" type="file">
 <input type="submit" value="Send File">
 </form>
 <?php } else {
    echo $msg;
    
echo "<pre>".print_r($_FILES, true)."</pre>";
} ?> 
</body>
 </html>
dus de file staat uiteindelijk wel op de plek waar je hem neer wilt zetten, (dat is regel 12)

maar je script crasht zonder foutmelding voordat het bij regel 34 aankomt.

--
dan zou mijn eerste stap zijn om er zeker van de zijn dat de error reporing aan staat en hoog .
dit zet je bovenin je script:
<?php
ini_set('display_errors', 1);
error_reporing(E_ALL);
?>


Krijg je dan nog geen foutmeling, dan zet je in het blok na regel 13 een paar keer:

<?php
echo 'regel : '. __LINE__ . '<br> ';
?>

om te zien waar je script strandt.




Reageren