I don't know how it is implemented. Let's share my methods.
On the page, I implemented it in this way.
I am adding data in the background.
First, we start to receive data. For example, the content of title and content. Determine whether the content is empty. if the content is empty, it is returned directly.
If there is an attachment, we need to determine whether there is an attachment. If there is an attachment, we first move it to the project's uploads folder through the program,
If it fails, we will return it directly.
Okay, go to the program.
If (IS_POST ){
$ Title = $ _ POST ['title'];
$ Content = $ _ POST ['content'];
If ($ title & $ content ){
If ($ _ FILES ['file'] ['name'])
// Start processing the submitted attachments.
If the attachment is successfully uploaded, you can obtain the attachment name, the uploaded address, and other information.
If it fails
An error is returned.
}
$ Arr = array (
'Title' => $ title,
'Content' => $ content;
'Filename' => ///
'Filepath' => ///
);
$ Flag = insert operation ..
If ($ flag) $ str = "successful ";
Else $ str = "failed ";
$ This-> success ("add". $ str, // jump to list route .);
}
} // End of post.
// The following is the template content ....
If we want to modify the content.
I thought of a method ..
On the page, if there is an attachment, We will display the image name. If you need to modify it, we will display the file submission box ..
I only wrote the key part ..
I got it done... it looks pretty on the front desk...
The background logic is a bit complicated ..
First, you must determine whether there are attachments. If there is no attachment, you cannot write null values into the database. If there is already one in the database, the user has not modified the attachment, if you write content to the database in a unified manner. will overwrite ..
Let me talk about my ideas.
First, judge whether the title and content are empty.
If it is not null, check whether there is an attachment. If there is an attachment, we will perform a unified receiving operation.
If (IS_POST ){
$ Title = $ _ POST ['title'];
$ Content = $ _ POST ['content'];
If ($ title & $ content ){
// Here we first define an array ..
$ Data = array ();
If ($ _ FILES ['file'] ['name'])
// Start processing the submitted attachments.
If the attachment is successfully uploaded, you can obtain the attachment name, the uploaded address, and other information.
If it fails
An error is returned.
Successful
$ Data ['filename'] = // file name
$ Data ['filepath'] = // file path.
}
$ Arr = array (
'Title' => $ title,
'Content' => $ content
);
If (! $ _ POST ['id']) {
$ Flag = insert operation ..
$ Type = "add ";
} Else {
$ Flag = perform the modification operation.
$ Type = "modify ";
}
If ($ flag) $ str = "successful ";
Else $ str = "failed ";
$ This-> success ($ type. $ str, // jump to the list route .);
}
} // End of post.
// The following is the template content ....