php - Importing a pre-uploaded file into a value field for a file upload -
i finishing off database entry aspect of project , have got 1 remaining snag that's interfering.
the database in mysql accessible via web site, includes posting new entries calling current entries , editing them before replacing originals.
so far works fine text based entries , can create form, populate old entries automatically, make corrections , resubmit, allowing updates without needing re-enter everything.
unfortunately, final part of selection of pictures. uploading process works fine cant find out how import value field upload box or if possible. because nature of upload code looks file think needs there work , importing address wont work. field uploading file shown below...
<div id="productpic" style="position:absolute;left:10px;top:280px;width:150px;height:16px;z-index:5;text-align:left;"> <span style="color:#000000;font-family:arial;font-size:15px;">product picture (main display):</span></div> <input type="hidden" name="size" value="50000000"> <input type="file" id="photo" style="position:absolute;left:180px;top:280px;width:200px;height:23px;line-height:23px;z-index:7;" name="photo" value="upload picture!">
because of this, if don't upload new file removes old 1 replacing plank entry. logic leads me think rather populate field old data need "if" statement determine if has been submitted unsure how incorporate it.
the script relating uploading file shown below:
//this directory images saved $target = "uploads/"; $target = $target . basename( $_files['photo']['name']); //this gets other information form //writes photo server if(move_uploaded_file($_files['photo']['tmp_name'], $target)) { //tells if ok echo "the file ". basename( $_files['uploadedfile']['name']). " has been uploaded, , information has been added directory"; echo "<br>,<br>"; } else { //gives , error if not echo "sorry, there problem uploading photo 1."; echo "<br>,<br>"; }
i've commented best can fast reading.
after file uploaded location saved mysql database using following code new location , write it.
$productpicture=($_files['photo']['name']); $data = "update `classifieds` set username='$nusername', productname='$nproductname', productdescription='$nproductdescription', productpicture='$productpicture', sellerspostcode='$nsellerspostcode', productprice='$nproductprice' id=".'"'.$key.'"'; $query = mysql_query($data) or die("couldn't execute query. ". mysql_error());
i think need create conditional if statement placing new picture location in database, if blank wont delete entry.
to create conditional "if" statement uploads database if required picture location fields filled?
i hope makes sense, ive been working on 12 hours day the last 2 weeks - first time doing php development.
thanks!
Comments
Post a Comment