Forum Moderators: coopster

Message Too Old, No Replies

Batch code execution?

         

ffoeg

2:59 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



Okay. I have a submit form that submits both text and images with the final image filename depending on the inserted text.

I insert all the content (text and image filenames) into a database for retrieval later.

My problem is this:
If I process each item individually (eg: text first, then image), then the errors produced are independant of each other. I'm not sure whether that makes sense, so let me elaborate.

If, say, I forget to enter the file, but do include the text, then the script will still insert the text into the database, but the image won't be uploaded.

Likewise, if the text is not entered, but the image is, the image is uploaded to the server whilst no entry is made into the database.

My question is whether there is any way to batch execute a bit of script? So basically, to make sure that there are no errors whatsoever before executing a specific piece of code?

And one other thing, my host doesn't allow me use

chmod
in my scripts. Is there any other way to change the permissions of a file/filder other than using and FTP client to manually change? What are the dangers of having a folder with write-read-execute permissions for everyone?

jatar_k

3:50 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you do them in two steps then maybe the best way is to have a third step, a verification script to check it all

you could also use a control script that executes each step of the process and then verifies it at the end

ffoeg

6:35 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



I'm not quite getting you there.

Do you mean two different sections of the script or two/three entirely different scripts?

jatar_k

8:20 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you were saying the images and text are done seperately, I didn't know if this was 2 parts of the same script or different ones

consider that each is acting as an individual action

make a third action that verifies the whole thing and and nukes stuff if both parts aren't there

what exactly are we talking about or what exactly are you trying to do?

there could be a different way to do it that would allow for better error checking.

ffoeg

2:13 pm on Feb 9, 2007 (gmt 0)

10+ Year Member



Sorry. when I say individually, I mean two parts of the same script.

Basically, what I want to do is have an option for a template. All that needs to be inserted into the form is a zip file, a preview image file, and a title.

The title is stripped of all invalid filename characters, and the image filename becomes whatever the stripped title is, plus the extension. Same for the zip file.

At the moment, the process happens that first the image is uploaded, then the zip file, then the database entry to store the values (title, image filename, zip filename).

Because this script runs through from start to finish, the main error that occurrs is that the image might upload, but there could be an error with with zip file or the database entry.

Then I would be stuck with an image file on the server, with no zip file or database entry to match.

Would a decent solution be to maybe set a value of

$error = true
every time an error occurrs. If $error is true, then whatever has been uploaded should be deleted. Right?

Thanks so much for being patient enough to try and understand :)

jatar_k

3:14 pm on Feb 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> If $error is true, then whatever has been uploaded should be deleted. Right?

that's exactly it, if everything does not occur successfully then the script needs to go back and clean up after itself

something like this

make sure title isn't empty
clean or validate title

upload image
is image ok?
if yes continue
if no delete temp image file, if there is one (depends on what failed) and die

upload zip
is zip ok?
if yes continue
if no then delete anything left from a bad zip upload and delete the image and die

insert data into database
insert ok?
if yes say thank you or redirect (whatever)
if no then delete zip and delete image and die

make sense?

ffoeg

6:28 am on Feb 10, 2007 (gmt 0)

10+ Year Member



Awesome stuff.

Thanks so much for the help. I really do appreciate it. It does make sense to me. There'll be some stuff that I'll have to learn, but that's fine for me :)