shadiadiph Posted February 27, 2009 Share Posted February 27, 2009 yo want them to be able to upload 12 images from the one form? Quote Link to comment Share on other sites More sharing options...
sungpeng Posted February 27, 2009 Author Share Posted February 27, 2009 yes Quote Link to comment Share on other sites More sharing options...
sungpeng Posted February 27, 2009 Author Share Posted February 27, 2009 anticipate your coding. Thank for help. 3.10am in singapore here. I will read your posting tmr morning. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 27, 2009 Share Posted February 27, 2009 i am in phuket so not so far away i wil send you something to try in a bit Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 27, 2009 Share Posted February 27, 2009 sorry changed alot but try this can work on inserting the error types and messages after it all works fine i am a bit confused by your update statement maybe you have to add somethng after it to make it insert i use an sql class which requires a different function to insert but on my server it just worked fine sorry too tired now to think about the errors the primary key id on the users table is pid right? sorry i got to go to sleep but i just tested this and it works creates the directory uploads to the file updates to the database but like i said maybe you need to add something else to make it insert to the database after where pid=$pid"); let me know anyway <?php ini_set ('upload_max_filesize','10M'); ini_set ("display_errors", "1"); error_reporting(E_ALL); include 'config2.php'; $pid = $_GET["pid"]; if($_POST[action]=="Update") { $pid = $_GET["pid"]; $email = $_POST["email"]; $pass = $_POST["pass"]; $fileatt_name = $_FILES['imagefile']['name']; $attachment1 = $fileatt_name[0]; $attachment2 = $fileatt_name[1]; $attachment3 = $fileatt_name[2]; $attachment4 = $fileatt_name[3]; $attachment5 = $fileatt_name[4]; $attachment6 = $fileatt_name[5]; $attachment7 = $fileatt_name[6]; $attachment8 = $fileatt_name[7]; $attachment9 = $fileatt_name[8]; $attachment10 = $fileatt_name[9]; $attachment11 = $fileatt_name[10]; $attachment12 = $fileatt_name[11]; $check_result=0; $check_login=mysql_query("select * from users where email='$email' and passwd='$pass' and pid='$pid'"); $check_result=mysql_num_rows($check_login); } if($check_result>0) { if (file_exists("photo/$pid")) { } else { mkdir("photo/$pid", 0755); } foreach ($_FILES["imagefile"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['imagefile']['tmp_name'][$key]; $fileatt_type = $_FILES['imagefile']['type'][$key]; $fileatt_name = $_FILES['imagefile']['name'][$key]; move_uploaded_file($fileatt, "photo/$pid/$fileatt_name"); } } $update_pdt=mysql_query("update users set imgdata1='$attachment1', imgdata2='$attachment2', imgdata3='$attachment3', imgdata4='$attachment4', imgdata5='$attachment5', imgdata6='$attachment6', imgdata7='$attachment7', imgdata8='$attachment8', imgdata9='$attachment9', imgdata10='$attachment10', imgdata11='$attachment11', imgdata12='$attachment12' where pid=$pid"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Upload an image to a database</title> </head> <body> <? $get_pdt_info=mysql_query("select * from instructor where pid=$pid"); $pdt_row=mysql_fetch_array($get_pdt_info); ?> <h2>Update with new information</h2> <form name="form" enctype="multipart/form-data" method="post" action="<?="$PHP_SELF?&pid=$pid";?>"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> Please insert the images<br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <input type='file' name='imagefile[]'><br /> <br> <br> USER : <input name="user"><br> PASSWORD : <input name="pass"><br> <input type="submit" name="action" value="Update"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 28, 2009 Share Posted February 28, 2009 you know you could just do foreach ($_FILES as $k => $v) { // and use $v instead of $_FILES['whatever'] } Quote Link to comment Share on other sites More sharing options...
sungpeng Posted February 28, 2009 Author Share Posted February 28, 2009 hi shadiadiph, Thank for the effort, I think the code allow all type of file to upload as I only require jpg file to upload for security reason. Is there a way? Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 give me few minutes Quote Link to comment Share on other sites More sharing options...
sungpeng Posted February 28, 2009 Author Share Posted February 28, 2009 I also see it does not unlink (delete) previous images. Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 almost have it worked out 5 more minutes Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 sorry i can't figure this out. i know that it os something like this but can't figure out where it goes in this the script i made for you did the same as what you wanted but mine allowed any file. i know the code you need to add is somethig like if ((($_FILES["imagefile"]["type"]=="image/jpeg") || ($_FILES["imagefile"]["type"]=="image/jpeg")) && ($_FILES["imagefile"]["size"] < 10000000)) { i have been trying for a couple of hours now and got no where. if you leave it as it was and add <? if ($error ==4) { print "You can only add jpg files that are under 500kb"; } ?> i your head of your html part it returns error 4 which you can read up on at http://th.php.net/manual/en/features.file-upload.errors.php sorry i can't be of any more help but this is driving me nuts Quote Link to comment Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 try this haven't tested it properly change it from here copy and paste this down to where it says move_uploaded_file($fileatt, "photo/$pid/$fileatt_name"); } } if (file_exists("photo/$pid")) { } else { mkdir("photo/$pid", 0755); } $fileatt_type = $_FILES['imagefile']['type']; for ($i=0;$i<count($fileatt_type);$i++) { if ($fileatt_type[$i]=="image/pjpeg") { foreach ($_FILES["imagefile"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $fileatt = $_FILES['imagefile']['tmp_name'][$key]; $fileatt_type = $_FILES['imagefile']['type'][$key]; $fileatt_name = $_FILES['imagefile']['name'][$key]; move_uploaded_file($fileatt, "photo/$pid/$fileatt_name"); } } } else { $message="You can only upload jpeg files of less than 500kb"; } } then add <body> <? print $message; ?> to your body Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.