3

此代码正在运行。它使用 webcam.js 保存照片。问题是当我用 Peña 的文件名保存文件时它不起作用。我得到了 Peña.jpg 或 Pe?a.jpg 文件名的结果。但在数据库中我做对了(peña)。

问题出在 file_put_contents 和 rename 函数上。

 $photoname = $_POST['photoname'];
    $date1 = date('Ymd');
    $photo_file = 'photos/'.$date.'/'.$date."".$photoname.".jpg";
    $encoded_data = $_POST['mydata'];
    $binary_data = base64_decode( $encoded_data );

    if (!is_dir('photos/' . $month)) {
      // dir doesn't exist, make it
      mkdir('photos/' . $month);
    }

    /*get the image */
    $result = file_put_contents($photo_file, $binary_data);

重命名功能(它也可以在没有特殊字符的情况下工作)。

$fname = utf8_decode($_POST['fname']);
$mname = utf8_decode($_POST['mname']);
$lname = utf8_decode($_POST['lname']);

$photo_old = $_POST['photopath'];
$photoname = utf8_decode(strtolower($fname. ''. $mname.''.$lname));
$date1 = date('Ymd');
$month = date('Ymd');
$photo_final = 'photos/'.$month.'/'.$date1."".$photoname.".jpg";
rename($photo_old, $photo_final);

结果:

Warning: rename(photos/20150929/20150929Peña.jpg,photos/20150930/20150930Pe?a.jpg)
4

0 回答 0