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 ?

[code] en [/code]

Ik vermoed dat je geen rechten hebt om in de /tmp te schrijven. Heb je de server in eigen beheer?
Heeft denk ik niets met PHPMailer te maken maar met de functie move_uploaded_file().
Op regel tien gaat het niet helemaal goed als je het mij vraagt. in $uploadfile zou een volledig path moeten komen naar een directory met voldoende schrijfrechten.

Stel dat de documentroot van je website dit is:

/var/www/html

en je maakt daarin een directory uploads met voldoende schrijfrechten

dan zou er in $uploadfile moeten komen:

/var/www/html/uploads/3ed3186da55a7462dffaeaec5f1449ac0227e16500mHVo

Plaats dus ook even een echo $uploadfile; zodat je kan zien hoe het path er uit ziet.
Ik heb een cpanel account
Ik kan hand matig wel een map aanmaken in /tmp.

Hoe moet ik dit formuleren ben niet bekend met de functies hier onder
 $uploadfile = tempnam(sys_get_temp_dir(/var/www/html/uploads/), sha1($_FILES['userfile']['name']));

Probeer eens dit:

<?php
echo $uploadfile;
?>

/tmp/3ed3186da55a7462dffaeaec5f1449ac0227e16500mHVo "
Krijg ik dit te zien
Dus je wilt de temp-file naar zichzelf verplaatsen.
Dat gaat niet.

Geef een ander/goed path in.
Waar moet ik dat pad ingeven en waar schrijf ik dat?
Zeg dat mijn pad /upload is waar komt dat te staan en is dit dat een permanente of tmp file
$uploadfile = '/upload/naam.ext';
<?php
$uploadfile = "/uploads/".sha1($_FILES['userfile']['name'];
?>

Dan moet je zelf even een map in je webroot aanmaken die 'uploads' heet, en die eventueel schrijfrechten geven (755 of anders 777)
Jordy R op 29/12/2014 13:53:41

is dit dat een permanente of tmp file


Permanent.

Reageren