php - upload many images with they label -
I need to upload 5 images with the people on which I created it before uploading many images Given, but it works fine
Take a look at my code.
This is the HTML code
& lt; Form action = "& lt ;? Php $ _SERVER ['PHP_SELF']? & Gt;" Method = "post" enctype = "multipart / form-data" & gt; & Lt ;? Php if (isset ($ _ GET ['msg'])) {$ msg = $ _ get ['msg']; Echo $ msg;}? & Gt; & Lt; Span style = "font-weight: bold; color: # F00," & gt; * ملحوظة ki & lt; / Span & gt; الصورة الأولي التي سترفع ستكون صورة المشروع الأساسية نرجوا أختيارها بعناية & lt; P & gt; & Lt; = Label for "img1" & Gt; Travel 1 & lt; / Labels & gt; & Lt; Input type = "file" name = "img []" id = "fileField1" /> & Lt; Input type = "text" name = "limage []" id = "Limage1" placeholder = "add label" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label = "img2" & gt; Travel 2 & lt; / Label & gt; & Lt; Input type = "file" name = "img []" id = "fileField2" /> & Lt; Input type = "text" name = "limmet []" id = "limage2" placeholder = "add label" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label = "img3" & gt; Travel 3 & lt; / Label & gt; & Lt; Input type = "file" name = "img []" id = "fileField3" /> & Lt; Input type = "text" name = "limmet []" id = "Limage3" placeholder = "add label" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label = "img4" & gt; Suffer 4 & lt; / Label & gt; & Lt; Input type = "file" name = "img []" id = "fileField4" /> & Lt; Input type = "text" name = "limmet []" id = "limage4" placeholder = "add label" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Label = "img5" & gt; Travel 5 & lt; / Label & gt; & Lt; Input type = "file" name = "img []" id = "fileField5" /> & Lt; Input type = "text" name = "limmat []" id = "limage5" placeholder = "add label" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" name = "submit" id = "submit" value = "upload more images" & gt; & Lt; Input type = "submit" name = "submit" id = "submit" value = "I have finished" & gt; & Lt; / P & gt; & Lt; / Form & gt;
and this is my PHP to upload images
if (isset ($ _ POST ['submitcon'])) {$ target = '.. / images / projects /'; $ Num = 1; $ ProjectID = $ P; {$ Error == UPLOAD_ERR_OK} {$ tmp_name = $ _FILES ["img"] ["tmp_name"] {forewr ($ _FILES ["img"] ["error"] $ key as $ =) ] [$ Key]; $ Name = $ _FILES ["IMG"] ["name"] [$ K]; $ Label = $ _ post ['Limage']; Move_uploaded_file ($ tmp_name, "$ target / $ name"); $ PutData = "projects_images (id, label, image, image_id) INSERT VALUE ('', '$ name', '$ label', '$ projectID')"; $ Result = $ db- & gt; Query ($ putData) or die ($ db-> error); If ($ result) {header ('location: index.php? Cid = 9 & provident = 8 & p ='. $ P. '& Amp; msg = image has been uploaded successfully, upload Need to be uploaded after doing the plan to save and edit the project '); } And {echo "error"; }}}}? & Gt;
I edit the code and now I'm getting the name of the image instead of the label ?? Any help please
You set the label based on the key that you are already using in your foreach You are already doing this for file information.
$ label = $ _ POST ['Lim' ']] [$ key];
In addition, you are inserting the backwards side:
should be:
$ putData = "projects_images (id, label, image, image_id) in value ('', '$ label', '$ Name', '$ projectID') ";
Just make sure you save your data properly before entering the database.
Comments
Post a Comment