bahaa Posted August 28, 2011 Share Posted August 28, 2011 Hello, I want to upload two files with different extension at once, and I want each one of them to be stored in the database in different row. Does any body know how to handle that ? regards, Link to comment Share on other sites More sharing options...
HartleySan Posted August 28, 2011 Share Posted August 28, 2011 Well, two regular queries should suffice. The following is also an option: http://php.net/manual/en/mysqli.multi-query.php Also, you might be best to not store the actual file in the DB. Link to comment Share on other sites More sharing options...
bahaa Posted August 28, 2011 Author Share Posted August 28, 2011 My problem is with handling the multi upload not with the query I am trying this but i am getting Notice: Undefined offset: 2 in C:\wamp\www\Site\htdocs\admin\upload1.php on line 33 Notice: Undefined offset: 2 in C:\wamp\www\Site\htdocs\admin\upload1.php on line 34 <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_FILES['upload'])){ //target path for($i=0; $i <count($_FILES['upload']['name']); $i++){ $target_path = "../uploads/"; $file_name = strtolower($_FILES['upload']['name'][$i]); $temp_filename = $_FILES['upload']['tmp_name'][$i]; $file_size = $_FILES['upload']['size'][$i]; $file_type = $_FILES['upload']['type'][$i]; $file_extension = substr(strchr($_FILES['upload']['name'][$i],'.'), 1); //Convert all applicable characters to HTML entities $file_name = htmlentities($file_name); $file_type = htmlentities($file_type); //Validate the type.Should be JPEH or PNG $allowed = array('image/pjepg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png', 'image/gif', 'image/GIF', 'flv', 'FLV'); if(!in_array($file_type, $allowed)){ $errors[]="<p>إمتداد الملف الذي قمت بتحميله غير مصرح به.</p>"; }// end of if(in_array($_FILES['upload']['type'], $allowed)){ }// for($i=0; count($_FILES['upload']['name']); $i++){ if(empty($errors)){ //if everything went ok if(move_uploaded_file($_FILES['upload']['tmp_name'][$i], $target_path.$_FILES['upload']['name'][$i])){ if(file_exists($target_path.$_FILES['upload']['name'][$i])){ //Generate uniqe file name $unique_name = uniqid(md5(time())).".".$file_extension; //Rename the file to an uniqid version rename($target_path . $_FILES['upload']['name'][$i], $target_path . $unique_name); }//end of if(file_exists($target_path/$filename)){ }else { $unique_name = NULL; } }//if(isset($_FILES['upload }// end of if(empty($errors)){ ?> <form action="upload1.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <input type="file" name="upload[]" /> <input type="file" name="upload[]" /> <input type="submit" name="submit" value="send"/> </form> </body> </html> Can any body point out where is my mistake? Link to comment Share on other sites More sharing options...
HartleySan Posted August 29, 2011 Share Posted August 29, 2011 If you do a search for "PHP Notice: Undefined offset", you'll probably find what you're looking for. The gist though is that you're trying to reference an index in an array that either doesn't exist or has some other issue. Good luck resolving things. Link to comment Share on other sites More sharing options...
Recommended Posts