【问题标题】:I dont really understand this "move_uploaded_file" error我真的不明白这个“move_uploaded_file”错误
【发布时间】:2016-08-12 20:46:52
【问题描述】:

我认为我的问题出在我的

$dossier = "/AprimeWeb/img/";

我为我的 $dossier(英文为 $folder)尝试了很多东西

有了这个我得到了这个错误

警告:move_uploaded_file(/AprimeWeb/img/face_merrick.jpg):失败 打开流:没有这样的文件或目录 C:\UwAmp\www\AprimeWeb\admin\ajout-plaquette.php 第 44 行

警告:move_uploaded_file():无法移动 'C:\Users\theal\AppData\Local\Temp\php5F09.tmp' 到 '/AprimeWeb/img/face_merrick.jpg' 在 C:\UwAmp\www\AprimeWeb\admin\ajout-plaquette.php 第 44 行

我的代码:

require_once('connexion.php');

$return = array('success' => false);

$titre            = isset($_POST['titre']) ? $_POST['titre'] : null;
$lieu    = isset($_POST['lieu']) ? $_POST['lieu'] : null;
$annee    = isset($_POST['annee']) ? $_POST['annee'] : null;
$montant    = isset($_POST['montant']) ? $_POST['montant'] : null;
$prestation    = isset($_POST['prestation']) ? $_POST['prestation'] : null;
$detail    = isset($_POST['detail']) ? $_POST['detail'] : null;

//-----------------------

$fichier = basename($_FILES['image']['name']);


$extensions = array('.png', '.gif', '.jpg', '.jpeg');
$extension = strrchr($_FILES['image']['name'], '.');
$dossier = "/AprimeWeb/img/";
//-----------------------

if(!is_null($titre) && !is_null($lieu)  && !is_null($annee) && !is_null($montant) && !is_null($prestation) && !is_null($detail) && !is_null($fichier)) {

    $sql = 'INSERT INTO plaquettes SET titre = \'' . $titre . '\', lieu = \'' . $lieu . '\', annee = \'' . $annee . '\', montant = \'' . $montant . '\', prestation = \'' . $prestation . '\', detail = \'' . $detail . '\'';
    $return['success'] = $connexion->exec($sql);
}


if(!in_array($extension, $extensions))

{
     $erreurup = 'Vous devez uploader un fichier de type png, gif, jpg ou jpeg';
}

if(!isset($erreurup)) //S'il n'y a pas d'erreur, on upload
{

     $fichier = strtr($fichier,
          'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
          'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');

     if(move_uploaded_file($_FILES['image']['tmp_name'], $dossier . $fichier))

    {
    $reqimg = $connexion->prepare('INSERT INTO plaquettes SET img = \'' . $fichier . '\'');
    $reqimg->execute(array($fichier));
    $reqimg->closeCursor();}
else
{    
    echo 'Echec de l\'upload !';
}
}else
{
     echo $erreurup;
}


echo json_encode($return);`

我不知道将我的文本添加请求和我的图片添加请求分开是否好,但我更容易检查错误

感谢您的帮助,如果您能告诉我 $dossier 中的路径如何工作。

【问题讨论】:

    标签: php database image forms


    【解决方案1】:

    请尝试以下路径: $dossier = $_SERVER['DOCUMENT_ROOT'].'/AprimeWeb/img/';

    【讨论】:

    • 这也有效,我没有错误,但我的 $reqimg 不会在我的数据库的图像列中写入任何内容
    【解决方案2】:

    上传时,应使用完整路径。

    $dossier = 'C:/UwAmp/www/AprimeWeb/img/';

    还要确保img 文件夹是可写的。

    【讨论】:

    • 啊,这样更好,我没有错误,但我的数据库中没有“图像”列:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-19
    • 1970-01-01
    • 2011-12-19
    相关资源
    最近更新 更多