Im trying to upload multiple image with caption, caption where user can edit and update the caption.
i dont have any problem for multiple image upload but couldn’t figure our how add caption for each upload image with edit/update option.
The field name needs to be an array, like what the field name of the type=‘file’ field is, with the array index being the id (autoincrement primary index) corresponding to the database table row that the image is in. When the data is submitted, you can use a foreach() loop to get both the array index (id) and the submitted value.
Your upload file handling code MUST detect if the total size of the form data has exceed the post_max_size setting (both the $_FILES and $_POST arrays will be empty), and then it must test to make sure that each individual file was uploaded without any error, the [‘error’] element will be a zero, before using any for the uploaded file information.
Computers don’t do random very well. Your existing code must detect and handle duplicates.
A better way to uniquely name things is to insert the row of data, get the autoincrement last insert id from that query, and use the id as part of the name. Since the autoincrement primary index is guaranteed to be unique, there’s no chance of duplicates.
You should also use a prepared query whenever you are supplying external, unknown, dynamic values to a query when it gets executed so that any sql special characters in a value won’t break the sql query syntax, which is how sql injection is accomplished. If you are avoiding doing this because of how hard it is with the mysqli extension, switch to the much simpler PDO extension.
Edit: Another issue with the upload code is you need to display a helpful error message for each uploaded file that has either failed to upload or to validate, so that the user can correct the problem and re-upload the failed file(s.)
Given that the <form… tag in the upload code won’t upload files, I’m guessing you are using ajax to submit that upload form data?
If you are also using ajax to submit the caption edit/update form data, what debugging have you done to find out if any data was submitted, what values were submitted, and what the server-side code did?
And, actually that just caused me to see the most likely problem. When using ajax to submit a form, the submit button isn’t a successful form field, and won’t automatically be set in the form data. This is the reason why we continually tell people to instead always detect if a post method form was submitted.
Also, putting the form processing code in the middle of the form ‘can’ work (the current code will break the output of the caption forms due to reusing variable names), but the post method form processing code should always be above the start of the html document and in the case of using ajax you would then need to output any user/validation errors or success messages back to the ajax code, and end php code execution.
in database im just storing image name without it’s extension… e.g pciture-1 but i want name with extension in database table like picture-1.jpg how can i achieve image with extension