Now that we can successfully upload a file for an individual article we can associate the file name
with the article rijkaard in the database.
Let's add a new column to the article table.
After they published at column at the end we'll call it image file.
And as the file name is a string We'll set the type as varchar with a length of two hundred characters.
File names could be longer than this but it's unlikely.
And later on will restrict the length of the file name in the code.
We want the default to be NULL which means the null attribute needs to be checked.
Our click save and there is the new column.
Then in the article class.
First let's add a property for this new field.
Then at the end of the script Let's add a method to update this field.
This won't be a static method as it's a method will call on an article object and will pass in the database
connection and the file name first let's add the s keywell.
Containing place holders file the image file and I columns.
Then we'll prepare it bind the values for the I.D. and image file and finally execute it returning the
execute methods boolean return value.
Let's add a p p Doug comment.
And then in the admen edit article image script.
First let's restrict the length of the file name to two hundred characters just in case it's longer.
Will do this after we've sanitized the file name.
The substring function returns part of a string but as the file name could contain utf Eight characters
will use the M.B substring function instead which does the same thing.
But it's safe for utf Eight strings.
So we'll call this method on the base variable.
Getting the part of the string from start which is character 0 to 200 characters.
Then when we've uploaded the file successfully we can call the new method in the article class passing
in the file name that we saved it with.
Then if this returns true we'll redirect to the admin articles show page.
Let's give that a try.
I'll not load an image.
And were redirected back to the admin article show page.
And in the rijkaard in the database the file name has been saved to the image file column.