当用户上传照片时,它会检查是否已有照片; 如果他们这样做,我希望它删除旧的(可能有任何扩展名),然后把新的.有没有办法在没有从数据库中获取旧扩展的情况下执行此操作?目前代码:
$del = $members->prepare("insert into profiles(userid, path, width, height, type, rtu, ext) values(?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE path = ?, width = ?, height = ?, type = ?, rtu = ?, ext = ?, time = NOW()");
$del->bind_param('sssssssssssss', $_SESSION['token'], $title, $file_info[0], $file_info[1], $file_info[2], $rh, $extension,
$title, $file_info[0], $file_info[1], $file_info[2], $rh, $extension);
$del->execute();
$new_file_name = "bb-x".$_SESSION['token'].".".$extension;
if ($del->affected_rows > 0) {
unlink('profiles/bb-x62'<any extension>);
}
$move_file = move_uploaded_file($file['tmp_name'], $upload_image_to_folder.$new_file_name);
Run Code Online (Sandbox Code Playgroud)
Cam*_* S. 11
代替 unlink('profiles/bb-x62'<any extension>);
使用这两行:
$file_pattern = "profiles/bb-x62.*" // Assuming your files are named like profiles/bb-x62.foo, profiles/bb-x62.bar, etc.
array_map( "unlink", glob( $file_pattern ) );
Run Code Online (Sandbox Code Playgroud)
这应该够了吧.
| 归档时间: |
|
| 查看次数: |
3106 次 |
| 最近记录: |