English 中文(简体)
PHP: 删除任何延期档案?
原标题:PHP: Delete a file with any extension?
  • 时间:2012-04-13 22:26:26
  •  标签:
  • php
  • file

当用户卸下照片时,它会检查他们是否已经拥有照片;如果他们想要删除旧照片(可能有任何延伸),然后将新照片带上。 如果没有从数据库获得原来的延期,是否有办法这样做? 现行法典:

        $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);
最佳回答

而不是<代码>unlink(简介/bb-x62 < 任何延伸>

利用这两行:

$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 ) );

这应当做到。

问题回答

您可以从受影响的名录服务器获得一份档案清单,并检索到同一档案名称的条目,直到有线和延伸。 从服务器数据中获取全称,删除该档案。 删除一个非常相似的档案名称有某种风险,但除了延期外,你还可以在检查中确定档案名称。

诸如从数据库中获取全部档案名称等声音可能会减少服务器的麻烦和负荷。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签