big-dog1965 Posted May 26, 2009 Share Posted May 26, 2009 Is there a simple way to use a text box in a form to check if a directory exists and if it doesn’t create it? If it does then store file through a upload field on same form. If it doesn’t create it and store files to it. I’m using a mysql DB for storing data from form. part of the Process.php file $query = "INSERT into `".$db_table."` (Venue_Name,Gallery_Image_1,Gallery_Image_2,Gallery_Image_3,Gallery_Image_4,Gallery_Image_5,Gallery_Image_6,Gallery_Image_7,Gallery_Image_8,Gallery_Image_9,Gallery_Image_10) VALUES ('" . $_POST['Venue_Name'] . "','" . $_POST['Gallery_Image_1'] . "','" . $_POST['Gallery_Image_2'] . "','" . $_POST['Gallery_Image_3'] . "','" . $_POST['Gallery_Image_4'] . "','" . $_POST['Gallery_Image_5'] . "','" . $_POST['Gallery_Image_6'] . "','" . $_POST['Gallery_Image_7'] . "','" . $_POST['Gallery_Image_8'] . "','" . $_POST['Gallery_Image_9'] . "','" . $_POST['Gallery_Image_10'] . "')"; mysql_query($query); I have another form that the Venue_Name is created from by user. Link to comment https://forums.phpfreaks.com/topic/159752-creating-a-directory-and-storing-with-text-box-on-form/ Share on other sites More sharing options...
Cosizzle Posted May 26, 2009 Share Posted May 26, 2009 Please dont type with bold font it hurts my eyes. You use the term "simple" to loosely. Simple for me? It would take a few hours to do, but doable sure. Simple for a php guru sure why not. Some functions you might find useful. is_dir() http://ca2.php.net/is_dir basename() http://ca2.php.net/manual/en/function.basename.php fopen() http://www.php.net/function.fopen Link to comment https://forums.phpfreaks.com/topic/159752-creating-a-directory-and-storing-with-text-box-on-form/#findComment-842617 Share on other sites More sharing options...
redarrow Posted May 26, 2009 Share Posted May 26, 2009 hahahaha my eyes lol. could not re zest sorry. Link to comment https://forums.phpfreaks.com/topic/159752-creating-a-directory-and-storing-with-text-box-on-form/#findComment-842620 Share on other sites More sharing options...
big-dog1965 Posted May 26, 2009 Author Share Posted May 26, 2009 Well where is the guru when I need him/her I’ve found a function/scripts but have no idea how to incorporate it and stuff. this one looks like maybe would do it if I knew coding. Instead of folder name time() use the database field Venue_Name from another table to create the directory under gallery/gallery_images which is a sub directory from where this form is located at. Which might be coming from BASE_DIR part of this? My thought is in the form/process of the gallery form the text field would be where the person enters the venue_name on submit it would process the data to mysql and this here code would make the dir if not exist and place the uploaded images in it, if it did exist then upload to the dir. this is echoing stuff but unless a problem accurd the no echo of this mkdir stuff function handleError() { trigger_error('MY ERROR'); /** usage sample @handleError(); echo $php_errormsg; */ } // detect slash/backslash nomenclature dirname $path = dirname( __FILE__ ); $slash = '/'; strpos( $path, $slash ) ? '' : $slash = '\\'; define( 'BASE_DIR', $path . $slash ); $folder = time(); // folder name $dirPath = BASE_DIR . $folder; // folder path $rs = @mkdir( $dirPath, '0777' ); @handleError(); if( $rs ) { // print success information echo 'was done!'; echo '<br>folder: <a href="' . $folder . '">' . $folder . '</a>'; echo '<br>dirPath: ' . $dirPath; }else{ // print error information echo 'an error was occurred. Attempting create folder'; echo '<br>dirPath: ' . $dirPath; echo '<br>php_errormsg: ' . $php_errormsg; } Link to comment https://forums.phpfreaks.com/topic/159752-creating-a-directory-and-storing-with-text-box-on-form/#findComment-842677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.