动态创建文件,文件路径在服务器机器上不起作用


dynamicaly creating file ,file path not working on server machine

>我正在将画布保存到文件中。代码在上传文件夹中创建一个 png 文件。它在本地计算机上正常工作,但是当我尝试在服务器上运行它时,我无法在上传文件夹中找到该文件。我走错了路吗?

文件创建后,我

正在打印警报,因此我收到文件创建警报,但文件不仅在上传文件夹中创建。

if ( isset($_POST["image"]) && !empty($_POST["image"]) ) { 
    // get the image data
    $data = $_POST['image'];
    list($type, $data) = explode(';', $data);
    list(, $data)      = explode(',', $data);
    $data = base64_decode($data);
    //Image name
    $filename ="image". md5(uniqid()) . '.png';
    $file ='../upload/'.$filename;  
  // decode the image data and save it to file
    file_put_contents($file,$data);

}

确保目录 '../upload' 存在或先创建它