anf.etienne Posted February 17, 2009 Share Posted February 17, 2009 Hi, i have this code for uploading files onto a server and it works great but im stumped on just 1 thing....baring in mind im a newbie at php lol. I generate a random number at the start of the code (when the page loads), i have a php form lower down the page that submits to another code with the same page and uploads the images. The problem is the number that is generated when the page loads is never used because when you upload the images it generates another number and creates a new folder. Is there a different way i can do this so just 1 number is generated? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <? $random_digit=rand(0000000000,9999999999); ?> <head> <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> <meta name="author" content="ve-creative.com - future-resourcings.com" /> <meta name="description" content="Site Description Here" /> <meta name="keywords" content="keywords, here" /> <meta name="robots" content="index, follow, noarchive" /> <meta name="googlebot" content="noarchive" /> <link rel="stylesheet" type="text/css" href="css/layout.css" media="screen, projection, tv " /> <link rel="stylesheet" type="text/css" href="css/html.css" media="screen, projection, tv " /> </head> <body> <!-- #content: holds all except site footer - causes footer to stick to bottom --> <div id="content"> <!-- #header: holds the logo and top links --> <div id="header" class="width"> <img src="images/logo.gif" alt="Your logo goes here"/> <ul> <li><a href="">Home</a></li> <li><a href="http://www.theauctionwinners.com/main" target="_blank">The Auction Winners</a></li> <li><a href="">Contact Us</a></li> <li><a href="" class="last">Logout</a></li> </ul> </div> <!-- #header end --> <!-- #headerImg: holds the main header image or flash --> <div id="headerImg" class="width"></div> <script src="js/js.js" language="javascript"></script> <script type="text/javascript" src="tinymce/tiny_mce.js"></script> <script language="javascript" type="text/javascript"> /*tinyMCE.init({ mode : "textareas", theme : "advanced" });*/ </script> <!-- #menu: the main large box site menu --> <div id="menu" class="width"> <ul> <li> <a href="business01.html" target="_self" onfocus="blur()"> <span class="title ">Business Research</span> <span class="desc">Effective Business System</span> </a> </li> <li> <a href="testimonies.html" target="_self" class="forum" onfocus="blur()"> <span class="title ">Testimonies</span> <span class="desc style3">View the included layout</span> </a> </li> <li> <a href="templates.html" target="_self" onfocus="blur()"> <span class="title ">Template Optimizer</span> <span class="desc">Create Your eBay Template</span> </a> </li> <li> <a href="downloads.html" target="_self" onfocus="blur()"> <span class="title ">Downloads</span> <span class="desc">Free Useable Software</span> </a> </li> </ul> </div> <!-- #menu end --> <!-- #page: holds the page content --> <div id="page"> <!-- #columns: holds the columns of the page --> <div id="columns" class="widthPad"> <!-- Single column --> <div class="floatLeft width100"> <form id="form1" name="form1" enctype="multipart/form-data" method="post" action=""> <table width="700" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="177">Template</td> <td><select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)"> <option>item1</option> </select></td> </tr> <tr> <td>Title</td> <td><input name='title' type='text' value='' title='' size="75" maxlength="60" /></td> </tr> <tr> <td>Subtitle</td> <td><input name='subtitle' type='text' title='' value='' size="75" /></td> </tr> <tr> <td>Description</td> <script type="text/javascript"> tinyMCE.init({ mode : "exact" ,elements : "id_description" ,theme : "advanced" ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect" ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen" ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup," ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor" ,theme_advanced_toolbar_location : "top" ,theme_advanced_toolbar_align : "left" ,theme_advanced_statusbar_location : "bottom" ,theme_advanced_resizing : true ,theme_advanced_resize_horizontal : false ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups" }); </script> <td><textarea name="description" cols="75" id="id_description" style="width:450px; height:350px;" title=""></textarea></td> </tr> <tr> <td>General Information</td> <script type="text/javascript"> tinyMCE.init({ mode : "exact" ,elements : "id_general" ,theme : "advanced" ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect" ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen" ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup," ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor" ,theme_advanced_toolbar_location : "top" ,theme_advanced_toolbar_align : "left" ,theme_advanced_statusbar_location : "bottom" ,theme_advanced_resizing : true ,theme_advanced_resize_horizontal : false ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups" }); </script> <td><textarea style="width:450px; height:350px;" id="id_general" name="general" title=""></textarea></td> </tr> <tr> <td>Terms & Conditions</td> <script type="text/javascript"> tinyMCE.init({ mode : "exact" ,elements : "id_terms" ,theme : "advanced" ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect" ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen" ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup," ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor" ,theme_advanced_toolbar_location : "top" ,theme_advanced_toolbar_align : "left" ,theme_advanced_statusbar_location : "bottom" ,theme_advanced_resizing : true ,theme_advanced_resize_horizontal : false ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups" }); </script> <td><textarea style="width:450px; height:350px;" id="id_terms" name="terms" title=""></textarea></td> </tr> <tr> <td>About Us</td> <script type="text/javascript"> tinyMCE.init({ mode : "exact" ,elements : "id_about" ,theme : "advanced" ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect" ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen" ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup," ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor" ,theme_advanced_toolbar_location : "top" ,theme_advanced_toolbar_align : "left" ,theme_advanced_statusbar_location : "bottom" ,theme_advanced_resizing : true ,theme_advanced_resize_horizontal : false ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups" }); </script> <td><textarea style="width:450px; height:350px;" id="id_about" name="about" title=""></textarea></td> </tr> <tr> <td>Payment Methods</td> <td>PayPal <label> <input type="checkbox" name="checkbox" id="checkbox" /> <br /> Personal Cheques <br /> <input type="checkbox" name="checkbox2" id="checkbox2" /> </label></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2"><div align="center"><strong>NOTE:</strong> Please save your listing NOW before you upload your pictures</div> <!--mult.pictures--> <script type="text/javascript" src="js/jquery-1.2.6.js"></script> <script> <!-- $(document).ready(function(){ $("#generate").click(function(){ //xxxxxxxxx //$("#quote").show("slow"); //$("#quote p").load("resizePic.php"); //grayOut(true, {'zindex':'0', 'bgcolor':'#000000', 'opacity':'90'}); }); }); function editImage(id) { //window.open('resizePic.php?id='+id,'res','width=800, height=700, scrollbars=1'); $("#quote").show("slow"); document.getElementById("iframeresize").src='resizePic.php?id='+id; //$("#quote").load("resizePic.php?"+id); //grayOut(true, {'zindex':'50', 'bgcolor':'#000000', 'opacity':'90'}); } function cancelEdit() { document.getElementById("iframeresize").src=''; $("#quote").hide("slow"); } --> </script> <style> #quote { display:none; width:650px; height:1100px; border:2px solid #000000; background-color:#ebebeb; z-index:1000; } #quotewrapper { } </style> <div id="quotewrapper"> <div id="quote"> <div> <iframe src="" frameborder="0" width="100%" height="100%" id="iframeresize"></iframe> </div> <div style="margin:10px; text-align:center;"><a href="javascript:cancelEdit();">[Cancel Image editing]</a></div> </div> </div> <table width="100%" border="0" cellpadding="5"> </table> <a href="javascript:showhide('div_uploadnewimages');">[upload new images]</a> <div id="div_uploadnewimages" style="border:1px solid #999999; margin-bottom:10px; padding:5px; displaynone;"> <strong>Upload new images</strong><br /> <? $max_no_img=10; // Maximum number of images value to be set here echo "<form method=post action= enctype='multipart/form-data'>"; echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>"; for($i=1; $i<=$max_no_img; $i++){ echo "<tr><td>Images $i</td><td> <input type=file name='images[]' class='bginput'></td></tr>"; } echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>"; echo "</form> </table>"; ?> </div> <div style="text-align:left; margin-bottom:30px;"> <strong><u>Pictures</u></strong> <br /> <div> </div> </div> <!--end:mult.pictures--></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> <h1 align="center"> </h1> </div> <!-- Single column end --> </div> <!-- #columns end --> </div> <!-- #page end --> </div> <!-- #content end --> <? $folderIn=mkdir("upload/$random_digit", 0777); while(list($key,$value) = each($_FILES['images']['name'])) { if(!empty($value)) { $filename = $value; $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upload/$random_digit/$filename"; //echo $_FILES['images']['type'][$key]; // echo "<br>"; copy($_FILES['images']['tmp_name'][$key], $add); chmod("$add",0777); $full_path="http://ve-creative.com/test/4/$random_digit/$filename<br />"; print $full_path; $folderPath="http://ve-creative.com/test/4/$random_digit"; } } ?> <? $username="vecre0_tempU"; $password="auction"; $database="vecre0_templates"; // OPEN CONNECTION ---> $connection=mysql_connect("localhost","$username", "$password") or die("Unable to connect!"); mysql_select_db("$database") or die("Unable to select database!"); // EXECUTE QUERY ---> $query="INSERT INTO paths ( folderPath) VALUES( '".$folderPath."')"; //////-----> $result=mysql_query($query) or die("Error in query:".mysql_error()); //if ($result) //echo mysql_affected_rows()." row inserted into the database effectively."; // CLOSE CONNECTION ---> mysql_close($connection); ?> <!-- #footer: holds the site footer (logo and links) --> <div id="footer"> <!-- #bg: applies the site width and footer background --> <div id="bg" class="width"> <img src="images/logo.gif" alt="Your logo goes here"/> <ul> <li><a href="">Home</a></li> <li><a href="http://www.theauctionwinners.com/main" target="_blank">The Auction Winners</a></li> <li><a href="">Contact Us</a></li> </ul> </div> <!-- #bg end --> </div> <!-- #footer end --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/145542-folder-creation-and-uploads/ Share on other sites More sharing options...
gevans Posted February 17, 2009 Share Posted February 17, 2009 Are you testing to see if the form has been submitted? If not you'll be making a new directory everytime the page loads, not only on form submission Quote Link to comment https://forums.phpfreaks.com/topic/145542-folder-creation-and-uploads/#findComment-764157 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 yes i tested to see how it was operating..... no matter how i lay it out with the submission code on the same page it would create a new folder on reload. So i have had to keep it seperate now im trying to work out a way to route back to the page after submission with the generated number in a variable that i could use after its been made Quote Link to comment https://forums.phpfreaks.com/topic/145542-folder-creation-and-uploads/#findComment-764169 Share on other sites More sharing options...
gevans Posted February 17, 2009 Share Posted February 17, 2009 Add the generated number to a hidden field in your form if you really need to use the 'random number' from a previous page... <input type="hidden" value="<?php echo $rand_num ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/145542-folder-creation-and-uploads/#findComment-764196 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.