jason360 Posted July 21, 2011 Share Posted July 21, 2011 Hey guys, New to coding and I am stuck on fetching this array being uploaded by a external source. What code do I need on my php/server side to fetch this array (used print_r function): Array ( [photo_caption] => test1 [photo_details] => text2) I am using this code on my php server side to fetch it, but it only uploads the first letter of text: / Fetch the photo caption array $photo_caption1 = $_POST['photo_caption']; $photo_details1 = $_POST['photo_details']; $photo_story1 = $_POST['photo_story']; $photo_email = $_POST['photo_email']; Any help is much appreciated. Thanks!!! Jason Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/ Share on other sites More sharing options...
phpSensei Posted July 21, 2011 Share Posted July 21, 2011 Are you trying to make a file upload here? I am not sure about what you mean about uploading a text, unless you mean to the mysql database. Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1245790 Share on other sites More sharing options...
jason360 Posted July 21, 2011 Author Share Posted July 21, 2011 Sorry. Yes, i am trying to upload text to MySQL data base. Only the first letter for the phrase is appearing Thanks!! Jason Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1245822 Share on other sites More sharing options...
phpSensei Posted July 21, 2011 Share Posted July 21, 2011 Sorry. Yes, i am trying to upload text to MySQL data base. Only the first letter for the phrase is appearing Thanks!! Jason Okay, post the full code then please. Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1245828 Share on other sites More sharing options...
jason360 Posted July 21, 2011 Author Share Posted July 21, 2011 No problem, here it is (note using jqtouch, jquery, phonegap); Here is my upload from: [script] var options = new FileUploadOptions(); options.fileKey="photo_filename[]"; options.fileName= "file.jpg"; //options.mimeType="image/jpeg"; var params = new Object(); params.photo_caption = document.getElementById("value1").value; params.photo_details = document.getElementById("value2").value; options.params = params; var ft = new FileTransfer(); ft.upload(imageURI, "http://www.mysite.com/upload.php", win, fail, options); [/script] [html] <form> <ul class="edit rounded"> <li><textarea name="photo_caption" id="value1" placeholder="Title - *Required*" /></textarea></li> <li><input type="text" name="photo_details" id="value2" placeholder="Details" /></li> <li class="arrow"><a href="#" onclick="getPhoto(pictureSource.PHOTOLIBRARY);"><h1>Submit Photo</h1></a></li> </ul> <img style="display:none;width:60px;height:60px;" id="smallImage" src="" /> <img style="display:none;" id="largeImage" src="" /> </div> </form> [/html] Here is my server/php side: <?php include("config.inc.php"); // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preupload.php print_r($_POST); $photos_uploaded = $_FILES['photo_filename']; // Fetch the photo caption array $photo_caption1 = $_POST['photo_caption']; $photo_details1 = $_POST['photo_details']; $photo_story1 = $_POST['photo_story']; $photo_email = $_POST['photo_email']; // Swear filter1 function censor ($string) { if ($string) { // array of swear words and replacements $sweararray = array("ahole","anus","ash0le","ash0les","asholes","ass","assh0le","assh0lez","asshole","assholes","assholz","asswipe","azzhole","bassterds","bastard","bastards","bastardz","basterds","basterdz","Biatch","bitch","bithes","Blow Job","boffing","butthole","buttwipe","c0ck","c0cks","c0k","cawk","cawks","Clit","cnts","cntz","cock","cokhead","cock-head","cocks","CockSucker","cock-sucker","crap","cum","cunt","cunts","cuntz","dick","dild0","dild0s","dildo","dildos","dilld0","dilld0s","doinatricks","dominatrics","dominatrix","dyke","enema","f u c k","f u c k e r","fag","fag1t","faget","fagg1t","faggit","faggot","fagit","fags","fagz","faig","faigs","fart","flipping the ird","fuck","fucker","fuckin","fucking","fucks","Fudge Packer","fuk","Fukah","Fuken","fuker","Fukin","Fukk","Fukkah","Fukken","Fukker","Fukkin","g00k","gay","gayboy","gays","gayz","h00r","h0ar","h0re","gook","hell","hoar","hoor","hoore","jackoff","jap","jerk-ff","jisim","jiss","jizm","jizz","knob","knobs","knobz","kunt","kunts","kuntz","Lesbian","Lezzian","Lipshit","Lipshitz","masochist","masokist","massterbait","masstrbait","masstrbate","masterbaiter","masterbat","masterbates","Motha Fucker","n1gr","nastt","nigger","nigur","niiger","niigr","orafis","orgasim","orgasm","orgasum","oriface","orifice","orifiss","packi","packie","packy","paki","pakie","paky","pecker","peeenus","peeenusss","peens","peinus","pen1s","penas","penis","penus","penuus","Phuc","Phuck","Phuk","Phuker","Phukker","polc","polack","polak","Poonani","pr1c","pr1ck","pr1k","pusse","pussee","pussy","puuke","puuker","queer","queers","queerz","qweers","qweerz","qweir","recktum","rectum","retard","sadist","scank","schlong","crewing","semen","sex","sexy","Sh!t","sh1t","sh1ter","sh1ts","sh1tter","sh1tz","shit","shits","shitter","Sitty","Shity","shitz","Shyt","Shyte","Shytty","Shyty","skanck","skank","skankee","skankey","skanks","Skaky","slut","sluts","Slutty","slutz","tit","turd","va1jina","vag1na","vagiina","vagina","vaj1na","vajina","vulva","vulva","w0p","wh00r","wh0re","whore","xrated","xxx","b!+ch","bitch","blowjob","clit","arschloch","fuck","shit","ass","asshole","b!tch","b17ch","b1tch","bastard","bi+ch","boiolas","buceta","c0ck","cawk","chink","cipa","clits","cock","cum","cunt","dildo","dirsa","ejakulate","fcuk","fuk","fux0r","hoer","hore","jism","kawk","l3itch","l3i+ch","lesbian","masturbate","masterbat","masterbat3","motherfucker","s.o.b","mofo","nazi","nigga","nigger","nutsack","phuck","pimpis","pusse","pussy","scrotum","sh!t","shemale","shi+","sh!+","slut","smut","teets","tits","boob","boobs","b00bs","teez","testical","testicle","titt","w00e","jackoff","wank","whoar","whore","damn","dyke","fuck","shit","@$$","amcik","andskota","arse","asrammer","ayir","bi7ch","bitch","bollock","breasts","cabron","cazzo","chraa","chuj","Cock","cunt","d4m","daygo","dego","dick","dike","dupa","dziwka","ejackulate","Ekrem","Ekto","enculer","faen","fag","fancl","fanny","feces","feg","Felcher","ficken","fitt","Flikker","foreskin","Fotze","fuk","futkretzn","gay","gook","guiena","h0r","h4x0r","hell","helvete","hoer","honkey","Huevon","hui","injun","jizz","kanker","kike","lotzak","kraut","knulle","kuk","kuksuger","Kurac","kurwa","kusi","kyrpa","lesbo","mamhoon","masturba","merd","mibun","monkleigh","mouliewop","muie","mulkku","muschi","nazis","nepesaurio","nigger","rospu","paska","perse","picka","pierdol","pillu","pimmel","piss","pizda","poontsee","poop","porn","p0r","pr0n","preteen","pula","pule","puta","puto","qahbeh","queef","rautenberg","schaffer","scheiss","schampe","schmuck","screw","sh!t","sharmuta","sharmute","shipal","shiz","skribz","skurwysyn","sphencte","spic","spierdalaj","splooge","suka","b00b","testicle","titt","twat","vittu","wank","wetback","wichser","zabourah","tabernac"); $replacearray = array("****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****","****"); $newstring = str_ireplace($sweararray, $replacearray, $string); return $newstring; } } if ($photo_caption1) { $photo_caption= censor($photo_caption1); } if ($photo_details1) { $photo_details= censor($photo_details1); } if ($photo_story1) { $photo_story= censor($photo_story1); } //swear end while( $counter <= count($photos_uploaded) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_details`, `photo_story`, `photo_category`, `photo_email`) VALUES('0', '".addslashes($photo_caption[$counter])."','".addslashes($photo_details[$counter])."','".addslashes($photo_story[$counter])."','".addslashes($photo_email[$counter])."','".addslashes($_POST['category'])."')" ); $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file move_uploaded_file($photos_uploaded['tmp_name'][$counter], $images_dir . '/' . $filename); // ---------- Include Adams Universal Image Resizing Function -------- include_once("ak_php_img_lib_1.0.php"); $target_file = "$images_dir/$filename"; $resized_file = "$images_dir/$filename"; $wmax = 320; $hmax = 480; ak_img_resize($target_file, $resized_file, $wmax, $hmax, $extention); // ----------- End Adams Universal Image Resizing Function ----------- // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$filename ); if($size[0] > $size[1]) { $thumbnail_width = 100; $thumbnail_height = (int)(100 * $size[1] / $size[0]); } else { $thumbnail_width = (int)(100 * $size[0] / $size[1]); $thumbnail_height = 100; } // Build Thumbnail with GD 2.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = 'ImageCreateFrom' . $function_suffix; $function_to_write = 'Image' . $function_suffix; // Read the source file $source_handle = $function_to_read($images_dir . '/' . $filename); if ($source_handle) { // Let's create a blank image for the thumbnail $destination_handle = ImageCreateTrueColor($thumbnail_width, $thumbnail_height); // Now we resize it ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]); } // Let's save the thumbnail $function_to_write($destination_handle, $images_dir . '/tb_' . $filename); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />"; } } $counter++; } // Print Result echo <<<__HTML_END <html> <head> <title>Photos uploaded</title> </head> <body> $result_final </body> </html> __HTML_END; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1245836 Share on other sites More sharing options...
phpSensei Posted July 21, 2011 Share Posted July 21, 2011 Sorry. Yes, i am trying to upload text to MySQL data base. Only the first letter for the phrase is appearing Thanks!! Jason Which of the following only shows the first letter in the database $photo_caption1 = $_POST['photo_caption']; $photo_details1 = $_POST['photo_details']; $photo_story1 = $_POST['photo_story']; $photo_email = $_POST['photo_email']; or is it all of them? also print out all 4 variables right before the mysql insert query and let me know the output Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1245967 Share on other sites More sharing options...
jason360 Posted July 22, 2011 Author Share Posted July 22, 2011 Yes, it is all of them. I printed the variables: print_r($photo_caption1); < /br> print_r($photo_details1); The response was successful, the full text made it through. Response: Text < /br> text This is very strange...could the problem be on the mysql side? Note when i use the webpage upload form (this work correctly): I get this response from print_r($_POST): Array ( [category] => 1 [photo_caption] => Array ( [0] => text ) [photo_details] => Array ( [0] => text ) [photo_story] => Array ( [0] => text ) [photo_email] => Array ( [0] => text ) [submit] => Add Photos ) Array ( [0] => text ) Array ( [0] => text ) <?php include("config.inc.php"); // initialization $photo_upload_fields = ""; $counter = 1; // default number of fields $number_of_fields = 1; // If you want more fields, then the call to this page should be like, // preupload.php?number_of_fields=20 if( $_GET['number_of_fields'] ) $number_of_fields = (int)($_GET['number_of_fields']); // Firstly Lets build the Category List $result = mysql_query( "SELECT category_id,category_name FROM gallery_category" ); while( $row = mysql_fetch_array( $result ) ) { $photo_category_list .=<<<__HTML_END <option value="$row[0]">$row[1]</option>\n __HTML_END; } mysql_free_result( $result ); // Lets build the Photo Uploading fields while( $counter <= $number_of_fields ) { $photo_upload_fields .=<<<__HTML_END <tr> <td> Photo: <input name=' photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <br> <textarea name='photo_caption[]' cols='30' rows='1'></textarea> <br> Details: <br> <textarea name='photo_details[]' cols='100' rows='2'></textarea> <br> Story: <br> <textarea name='photo_story[]' cols='100' rows='10'></textarea> <br> Email: <br> <textarea name='photo_email[]' cols='100' rows='1'></textarea> <br> </td> </tr> __HTML_END; $counter++; } // Final Output echo <<<__HTML_END <html> <head> <title>Lets upload Photos</title> </head> <body> <form enctype='multipart/form-data' action='upload.php' method='post' name='upload_form'> <table width='90%' border='0' align='center' style='width: 90%;'> <tr> <td> Select Category <select name='category'> $photo_category_list </select> </td> </tr> <tr> <td> <p> </p> </td> </tr> <!-Insert the photo fields here --> $photo_upload_fields <tr> <td> <input type='submit' name='submit' value='Add Photos' /> </td> </tr> </table> </form> </body> </html> __HTML_END; ?> Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1246276 Share on other sites More sharing options...
jason360 Posted July 22, 2011 Author Share Posted July 22, 2011 I am wondering if it is because the arrays are not matched up: Webpage upload form(works correct) response: Array ( [category] => 1 [photo_caption] => Array ( [0] => text ) [photo_details] => Array ( [0] => text ) [photo_story] => Array ( [0] => text ) [photo_email] => Array ( [0] => text ) [submit] => Add Photos ) Array ( [0] => text ) Array ( [0] => text ) Phonegap upload response: Array ( [photo_caption] => Text [photo_details] => text [photo_email] => text [photo_story] =>text) Quote Link to comment https://forums.phpfreaks.com/topic/242562-phpserver-side-upload-problem/#findComment-1246279 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.