如何从文件夹中取消链接图像?

时间:2022-06-01 03:31:53

I am currently working on shopping cart.let me quick expain whats happening in product_info.php page.

我目前正在购买cart.let我快速了解product_info.php页面中发生的事情。

in product info page products information in displayed such as name,price,image etc..

在产品信息页面中显示的产品信息,如名称,价格,图像等。

i have made small functionality in this page.i have put 10 small diffrent color images below the product main image and 2 text boxes to write something on main image using php Gd.

我在这个页面上做了一些小功能。我在产品主图像和2个文本框下面放了10个小的不同颜色图像,用php Gd在主图像上写东西。

i have made ajax function which is called on onclick of image small images and on onkeyup of two text boxes with three parameter : selected color image's path and value of textboxes.Now when user will click on the one of the color image or Write text in the text box then this function will call and the response will go in the img.php file in which the dynamic image is created using GD and stored in the folder(not in databse) with random image integer name and this image. and from img.php it will get in product info page and display in main image.this new image's path will store in session for when user done checkout then it will store in table.

我已经制作了一个ajax函数,它被调用图像小图像和两个文本框的onkeyup上有三个参数:选择彩色图像的路径和文本框的值。现在当用户点击其中一个彩色图像或写入文本时然后该文本框将调用该函数并且响应将进入img.php文件,其中使用GD创建动态图像并将其存储在具有随机图像整数名称和此图像的文件夹(不是数据库中)中。从img.php它将进入产品信息页面并显示在主图像中。这个新图像的路径将存储在会话中,当用户完成结账时,它将存储在表格中。

same process will repleat when user select diffrent color or eneter diffrent value in text box and every time new image will create and save in folder.

当用户在文本框中选择不同颜色或不同的值时,每次新图像将创建并保存在文件夹中时,相同的过程将重新进行。

my question is how woulld i unlink the previous image from folder when new image will create? Thanx In Advance.

我的问题是,当新图像创建时,我如何取消链接文件夹中的上一个图像? Thanx提前。

4 个解决方案

#1


0  

Your question is very hard to read, but overall

你的问题很难阅读,但总的来说

unlink($imageName);

Will delete the image, as documented here.

将删除图像,如此处所述。

Since the file is already sent to the client, you can unlink it right away when the image needs to be updated (in img.php if I understood properly?).

由于文件已经发送到客户端,您可以在需要更新图像时立即取消链接(如果我理解正确的话,在img.php中)。

#2


0  

When saving your GD image for the user, you need to use a key that can be linked to the user and the image and the colour. The when you unlink the image, you can search for that key, colour and image combo and remove it.

为用户保存GD图像时,需要使用可以链接到用户以及图像和颜色的键。当您取消链接图像时,您可以搜索该键,颜色和图像组合并将其删除。

For example, save the images with a name like this: uid_imgId_colourId.ext. If you want to add a small random id, that may help as well, but add it to the end of the file name (before the .ext).

例如,使用如下名称保存图像:uid_imgId_colourId.ext。如果你想添加一个小的随机id,这也可能有帮助,但是将它添加到文件名的末尾(在.ext之前)。

#3


0  

Use unlink function to delete the image.

使用取消链接功能删除图像。

first check rather the file is there or not.

首先检查文件是否存在。

  unlink('\path\image_name1.png');

#4


0  

first check rather the file is there or not and after fetch image name in database

首先检查文件是否存在以及在数据库中获取图像名称之后

unlink("image path/imagename");

#1


0  

Your question is very hard to read, but overall

你的问题很难阅读,但总的来说

unlink($imageName);

Will delete the image, as documented here.

将删除图像,如此处所述。

Since the file is already sent to the client, you can unlink it right away when the image needs to be updated (in img.php if I understood properly?).

由于文件已经发送到客户端,您可以在需要更新图像时立即取消链接(如果我理解正确的话,在img.php中)。

#2


0  

When saving your GD image for the user, you need to use a key that can be linked to the user and the image and the colour. The when you unlink the image, you can search for that key, colour and image combo and remove it.

为用户保存GD图像时,需要使用可以链接到用户以及图像和颜色的键。当您取消链接图像时,您可以搜索该键,颜色和图像组合并将其删除。

For example, save the images with a name like this: uid_imgId_colourId.ext. If you want to add a small random id, that may help as well, but add it to the end of the file name (before the .ext).

例如,使用如下名称保存图像:uid_imgId_colourId.ext。如果你想添加一个小的随机id,这也可能有帮助,但是将它添加到文件名的末尾(在.ext之前)。

#3


0  

Use unlink function to delete the image.

使用取消链接功能删除图像。

first check rather the file is there or not.

首先检查文件是否存在。

  unlink('\path\image_name1.png');

#4


0  

first check rather the file is there or not and after fetch image name in database

首先检查文件是否存在以及在数据库中获取图像名称之后

unlink("image path/imagename");