move_uploaded_file移动到同一文件夹,没有错误


move_uploaded_file moving to same folder, no errors

我有以下json查询发布到我的PHP文件,其中"上传的文件"是将base64转换为"xxx"文件类型:

$http.post(
    preUrl + 'assets/new.php',
    data
);

我在响应中没有收到任何错误,一切似乎都过渡得很好。以下是我在PHP中的代码:

$fileExt = explode("image/", $_POST["poster"])[1];
$fileExt = explode(";", $fileExt)[0];
$filename = uniqid(md5($_POST["poster"])).".".$fileExt;
$poster = convert2image($_POST["poster"], $filename);
/*Everything up to here works as expected, convert2image converts from b64 to file format*/
move_uploaded_file($poster, "/var/www/vhosts/xxxxxx.org/i.xxxxxx.org/uploads/".$poster);
/*This last line doesn't seem to work, the file is saved into the same directory where the PHP file is*/

这是我的转换2image脚本,也许这与它有关?

function convert2image($b64, $output_file){
    $ifp = fopen($output_file, "wb");
    $data = explode(',', $b64);
    fwrite($ifp, base64_decode($data[1]));
    fclose($ifp);
    return $output_file;
}
move_uploaded_file仅用于在

文件输入字段中上传到 php.ini config 中指定的 tmp 文件夹中

的文件

在您的情况下,您应该使用复制重命名

上。此外,用一个名称保存文件并在重命名后保存文件也是没有用的。