The title might be messed up a bit; I didn't know how else to title it...

Basically I'm making a web page for a guy who sells sports memorabilia/penants/team clocks, etc. for free as a favor, and I'm making the item create page where you type in the name of the item, which team you want to associate it with, price, etc..

Well he also wants images obviously. The item create page then uses POST to send the information to the next page, where you can preview it and if you like the information, you can click on the create button, but if you want to change something, you can edit the information below and do it again until you like the information, then create the item.

But what I don't quite understand, is, is there a way to NOT save an uploaded image, for example, just to preview the item with the image, but if you actually do not end up creating the item, having the php script NOT save the picture?

Here's what I do know. I know how to upload images and files just fine. They are uploaded to a temp directory (on UNIX, which is the system I'm using), and then you have to move the file to a directory of your choice, otherwise the temp file will be deleted upon completion of the script.

But is there a way to sort of keep a copy of it so that if you notice a spelling mistake you made in the item description, you can correct it, then click preview again, WITHOUT having to re-upload the image......but also having it so that if you DON'T create the item......no copy of the image is saved?

Does this make sense, or do I have to explain it a different way? I want to make it as easy as possible for him because he doesn't know much about computers, and make it so that he has to do as little entering of data as possible, especially if he already entered it, such as text and the image.

Thanks much
diode

Its not possible to not save the image, however if it has already been uploaded you can display it in the second edit stage and if another image is not chosen again, to use the one already uploaded. You can also unlink() it if the whole thing is canceled.


Matti Ressler
Suomedia

I think I understand what you are asking and I'm not too sure how you are going to get it right.

You might have to do the move to the new folder so that the image is available for whatever occurs and then delete the image if the order does not go through by using the unlink() command:

$myFile = "testFile.txt";
unlink($myFile);

Hope this helps!

Like mentioned, you'll have to move the image away from the upload folder since it would be deleted otherwise (as you mentioned).

A bit off topic:

Something to remember is that you can never rely on the user to do something for you. In this case accept or reject the image preview. So you'll need to have a cleanup of the temporary folder every now and then.

You can use the modification time of the file to see if its expired (old) or delete all the unapproved files for a user when their session expires.

Normally this isn't a problem with just a few users, but it is easily a problem on large numbers of users.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.