PHP - Php Rename Image To Input Field
Hi All,
Need help. I have a form which collect the users information including image which are stored in the directory. I want to rename the image file to the name of the user and stores it relative path in SQL table so that when I retrieve user name it also retrieve the image of the user. My Table structure is as follow: id int(5) lecturer_name varchar(10) lecturer_img_path varchar(100) Below is the PHP and HTML code. PHP Code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname)or die ('Error connecting to mysql'); ?> <?php if(isset($_POST['lecturer'])) { $lecturer = $_POST['lecturer']; $n = count($lecturer); $i = 0; echo "Your selected lecturer are \r\n" . "<ol>"; while ($i < $n) { if($lecturer[$i] == ""){ //do nothing $i++; }else{ echo "<li>{$lecturer[$i]}</li> \r\n"; $i++; } } echo "</ol>"; } ?> <?php mysql_close($conn); ?> HTML FORM Code: [Select] <!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>lecturer details</title> <style type="text/css"> body { background-color: #ffc; } </style> </head> <body> <b> <h1>Enter new lecturer details :</h1> <form id="form1" name="form1" method="post" action="submit1.php"> <p>Lecturer:<br /> <label for="lecturer"></label> <input name="lecturer[]" type="text" id="lecturer1" size="15" /> <label for="lect_img1"></label><input id="lect_img1" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer2" size="15" /> <label for="lect_img2"></label><input id="lect_img2" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer3" size="15" /> <label for="lect_img3"></label><input id="lect_img3" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer4" size="15" /> <label for="lect_img4"></label><input id="lect_img4" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer5" size="15" /> <label for="lect_img5"></label><input id="lect_img5" type="file" name="lect_img[]"><br /> <input name="lecturer[]" type="text" id="lecturer6" size="15" /> <label for="lect_img6"></label><input id="lect_img6" type="file" name="lect_img[]"><br /> <br /> <input name="submit" type="submit" id="send" value="submit"> </form> </b> </body> </html> Similar Tutorialsi am trying to display all the image from a dir and let the use lick on a image that takes them to other page where they can rename that image. or let them rename the image from the first page. here is what i have. Code: [Select] <?php SESSION_START(); ?> <!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"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="author" content="vs" /> <meta name="robots" content="index, follow" /> <title></title> </head> <body> <div id="centerColumn"> <div id="header"> </div> <p><span class="small"></span><br /> </p><br> <form method="post" action="data2file.php"> <?php echo ' <table> <tr><td>'; $username = $_SESSION['user']; $url = $username."./"; $handle = opendir ($url); while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".." && $file != basename(__FILE__)) { //echo '<table border=1><tr><td>'; echo '<a href="edit.php" ><img border=1 src="'.$file.'"></a>'; echo '<br />'; echo "<input type=submit name=$file value=Edit>" ; print $file; echo '<br>'; echo "Enter new name: <input type='text' name='new-name' length='30'> <textarea type=text size='1' height='1'style='display:none' name='file-name' >". $file ."</textarea>"; echo '<hr>'; //echo '</td></tr></table>'; } } echo '</td>'; echo ' </table>'; ?> </body> </html> it works i loads all the images. and here is the data2file.php code Code: [Select] <?php SESSION_START(); echo $_POST['new-name']; echo '<br>'; echo $_POST['file-name']; echo '<br>'; echo "Successfully!"; ?> it's just display the name of the file and the new name i want to give it. But it only does the last image in the dir. How can i make the first code work so if the user clicks on the edit button it will pull only that image file name to the data2file.php and then from the data2file.php it will rename the file name. I have a field in a table named flights I hope to find a 1 line statement to bypass inserting a new row if $flight_no is already in the field flight_no btw flight_no is the primary key and won't allow a duplicate anyway but I want to avoid the error message this is what I tried but doesn't work if(SELECT * FROM flights WHERE flight_no !LIKE %$flight_no%) { I am having trouble sending information that was entered into a form, on the same page to the next page. I am sure i have done this a few years ago but cant find the code and cant find the answer online, hope someone can help me. My code is as follows: <form method="POST" action="https://.............. .asp "> <table> <tr> <td>Name: </td> <td><input type="text" name="clientname" /></td> </tr> <tr> <td>E-mail:</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Contact No:</td> <td><input type="text" name="telno" /></td> </tr> </table> <?php $udate = date("y-m-d H:i:s", strtotime ("+2 hour")); $uniquevalue = "$udate" . " " . "Simpay Pro"; echo $uniquevalue; ?> <br /> <input type="hidden" name="info1" value="<?php print $uniquevalue?>"> <input type="hidden" name="info2" value=$clientname> <input type="submit" value="Submit"> </form> So basically info1 is working i can see the value on the next page after its submitted, but info2 is the value of the input field. Is this possible to do it like this, or do i have to send it to another page and then to my last page that displays the values? can someone tell me why this won't work? I just want to key in the amtpaid and have fields inserted. I get no errors but the only field inserted is the datepaid . <html><head> <script> function $_(IDS) { return document.getElementById(IDS); } function calculate_paid() { var amtpaid = parseInt($_("amtpaid").value); var rentdue = parseInt($_("rentdue").value); var prevbal = parseInt($_("prevbal").value); var secdep = parseInt($_("secdep").value); var latechg = parseInt($_("latechg").value); var damage = parseInt($_("damage").value); var courtcost = parseInt($_("courtcost").value); var nsf = parseInt($_("nsf").value); var hudpay = parseInt($_("hudpay").value); var late = ($_("late").value); var paidsum = parseInt($_("paidsum").value); var dateNow = new Date(); var dayNow = dateNow.getDate(); var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear(); $_('datePaid').value = datePaid; if(dayNow > 5) { late = "L"; prevbal = prevbal + 10; } paidsum = paidsum + amtpaid var tentpay = amtpaid - hudpay; var totOwed = rentdue + prevbal - hudpay; var left = totOwed - amtpaid; if (amtpaid <= totOwed) { prevbal = left; } left = amtpaid - totOwed; if (left <= secdep) { secdep = secdep - left; } left = left - secdep; if (left <= damage) { damage = damage - left; } left = left - damage; if (left <= latechg) { latechg = latechg - left; } left = left - latechg; if (left <= courtcost) { courtcost = courtcost - left; } left = left - courtcost; if (left <= nsf) { nsf = nsf - left; } prevbal = left - nsf; } </script> </head><body> <?php mysql_connect(localhost,root,""); mysql_select_db(test) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $apt = $_POST['apt']; $query="SELECT * FROM testdata Where apt='$apt'"; $result=mysql_query($query); if(mysql_num_rows($result)) { echo "<form action='#' method='post'><b>Rent Payment :<br /><br /> <table cellspacing=0 cellpadding=0 border=1> <tr> <th>Name</th> <th>Apt</th> <th>Paid</th> <th>Due</th> <th>Prev Bal</th> <th>Sec Dep</th> <th>Late Chg</th> <th>Dmg</th> <th>Court Cost</th> <th>NSF</th> <th>Tent Pay</th> <th>Hud Pay</th> <th>Date Paid</th> <th>Late</th> <th>Comments</th> <th>Paidsum</th> </tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr> <td><input type='text' size=25 name='name' value='" . $row['name'] . "'></td> <td><input type='text' size=2 name='apt' value='" . $row['apt'] . "' ></td> <td><input type='text' size=4 id='amtpaid' name='amtpaid' value='" . $row['amtpaid'] ."' onBlur='calculate_paid(this)'></td> <td><input type='text' size=4 id='rentdue' name='rentdue' value='" . $row['rentdue'] . "'></td> <td><input type='text' size=4 id='prevbal' name='prevbal' value='" . $row['prevbal'] ."'></td> <td><input type='text' size=4 id='secdep' name='secdep' value='" . $row['secdep'] ."'></td> <td><input type='text' size=4 id='latechg' name='latechg' value='" . $row['latechg'] ."'></td> <td><input type='text' size=4 id='damage' name='damage' value='" . $row['damage'] ."'></td> <td><input type='text' size=4 id='courtcost' name='courtcost' value='" . $row['courtcost'] ."'></td> <td><input type='text' size=4 id='nsf' name='nsf' value='" . $row['nsf'] ."'></td> <td><input type='text' size=4 id='tentpay' name='tentpay' value='" . $row['tentpay'] . "'></td> <td><input type='text' size=4 id='hudpay' name='hudpay' value='" . $row['hudpay'] ."'></td> <td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "'></td> <td><input type='text' size=1 id='late' name='late' value='" . $row['late'] . "'></td> <td><input type='text' size=25 name='comments' value='" . $row['comments'] . "'></td> <td><input type='text' size=4 id='paidsum' name='paidsum' value='" . $row['paidsum'] . "'></td> </tr>"; } echo "</table> <input type='submit' name='update' value='Make Payment' /> </form>"; } else{echo "No listing for apartment $apt.<br />Please select another.<br />";} } if(!empty($_POST["update"])) { $sql = "UPDATE testdata SET name = '" . mysql_real_escape_string($_POST['name']) . "', amtpaid = '" . mysql_real_escape_string($_POST['amtpaid']) . "', rentdue = '" . mysql_real_escape_string($_POST['rentdue']) . "', prevbal = '" . mysql_real_escape_string($_POST['prevbal']) . "', secdep = '" . mysql_real_escape_string($_POST['secdep']) . "', latechg = '" . mysql_real_escape_string($_POST['latechg']) . "', nsf = '" . mysql_real_escape_string($_POST['nsf']) . "', damage = '" . mysql_real_escape_string($_POST['damage']) . "', courtcost = '" . mysql_real_escape_string($_POST['costcost']) . "', tentpay = '" . mysql_real_escape_string($_POST['tentpay']) . "', hudpay = '" . mysql_real_escape_string($_POST['hudpay']) . "', datepaid = '" . mysql_real_escape_string($_POST['datepaid']) . "', late = '" . mysql_real_escape_string($_POST['late']) . "', comments = '" . mysql_real_escape_string($_POST['comments']) . "', paidsum = '" . mysql_real_escape_string($_POST['paidsum']) . "' WHERE apt='".$_POST["apt"]."'"; mysql_query($sql) or die("Update query failed."); echo "Record for apartment ".$_POST["apt"]." has been updated"; } ?><form method="post" action="#"> <br /> <input type="text" name="apt"/> <p> <input type="submit" name="submit" value="select apartment"/> </form> </body></html> Hiya pplz. I am trying to add: class="keyboardInput" to activate a javascript script to an input box. This is the line im trying to add it to: <td><?php echo form_input(array('name'=>'quantity','value'=>$item['quantity'],'size'=>'2'));?></td> I have tried: <td><?php echo form_input(array('name'=>'quantity','value'=>$item['quantity'],'size'=>'2'));? class="keyboardInput"></td> didn't work. Any help would be great. Ian I have a register script, and I am wanting to make it so that if the username field contains, lets say "mod", "ass", and more, then it'll return an error and wont let them register. Hello phpfreaks I'm a bit new to PHP, as well as this forum. I'm learning in a fast way, but there's something I can't seem to figure out, nor find it on google. I'm sure it's a simple and basic trick, but like I said, I'm just a beginner So the question is: How can I store multiple words to an array, using only 1 input form field? I guess it's with a for-loop..? So everytime you hit the 'submit' button, a new word should be added to the array. My problem is that I'm always overwriting ONE word.. This is what I've got so far.. : Code: [Select] <?php if (isset($_POST['word'])){ $word = $_POST['word']; $word = strip_tags($word); $word = trim($word); $word = htmlentities($word); } else { $word = ""; } ?> <div id="arrays"> <p>Add a word to the array below:<br /><br /></p> <form action="index.php" method="post"> <input id="word" name="word" type="text" value="<?php echo $word; ?>" /> <br /><input class="btn" type="submit" value="Submit" /> </form> <br /> <p> <?php $array = array("apple", "banana", "lemon", $word); for ($i = 0; $i < count($array); $i++){ echo $array[$i] . " "; } ?> </p> </div> Also: I'm using PHP 5, in combination with xHTML strict 1.0. Hi everyone. In the script below, I would like to have the input box for "Website" to have http:// already in that input field. So, people will see "Website:" and then in the input field it will have "http://" I'm a PHP novice, and I'm not sure how to do it. Thanks. Code: [Select] <?php $contact_form_fields = array( array('name' => 'Website:', 'type' => 'input', 'require' => 1), array('name' => 'Name:', 'type' => 'name', 'require' => 1), array('name' => 'E-mail:', 'type' => 'email', 'require' => 1), array('name' => 'Phone:', 'type' => 'input', 'require' => 0), array('name' => 'Service:', 'type' => 'select', 'require' => 1, 'default' => 'Select Desired Service', 'items' => array('Keyword Research', 'Search Engine Optimization', 'Link Building Services', 'SEO Web Design', 'SEO Copywriting', 'SEO Consulting', 'Conversion Optimization', 'Social Media and PR', 'Landing Page Optimization', 'Other')), array('name' => 'Budget:', 'type' => 'select', 'require' => 1, 'default' => 'Budget / Monthly', 'items' => array('$500-$1500', '$1500-$2500', '$2500-$5000', '$5000-$10000', '$10K +')), array('name' => 'Comments:', 'type' => 'textarea', 'require' => 1), array('name' => 'Turing number:', 'type' => 'turing', 'require' => 1, 'url' => 'contact-form/image.php', 'prompt' => 'Please enter the number displayed above'), ); $contact_form_graph = false; $contact_form_xhtml = true; $contact_form_email = "someone@somewhere.com"; $contact_form_encoding = "utf-8"; $contact_form_default_subject = "Sent from free SEO quote form"; $contact_form_message_prefix = "Sent from free SEO quote form\r\n==============================\r\n\r\n"; include_once "contact-form2/contact-form/contact-form.php"; ?> Hi, PHP newbie here, and my first post. I am in the process of learning PHP. Currently I am looking at forms and DB input. I would like to verify if my current method of keeping the linebreaks from a TEXTAREA field, and still keep the DB input safe is correct. I use the following code to get the input from the TEXTAREA field. Code: [Select] $comments = mysql_real_escape_string(nl2br(filter_var($_POST["comments"], FILTER_SANITIZE_STRING)));Is this the correct way of handling this? Thanks I would like to split the field specific location on a page into two fields. ( This is how it looks now: http://qwikad.com/?view=post&cityid=269&lang=en&catid=3&subcatid=27&shortcutregion= ) I want keep the same MySQL table for that field but make it possible for visitors to enter 2 separate texts. This is how the code looks right now: <input name="area" type="text" size="40" class="input" maxlength="50" value="<?php echo $data['area']; ?>"> I am not strong in PHP programming at all, so I tried to copy and paste that field twice, but it only posts one entry out of the two. Can this be done? Hi all First, thanks for any help you can offer! What I'm trying to do is have a form, when submitted, create an attachment (the attachment appends the form values if it is already created) AND send the form values to myself as well as the person filling in the form (so to the email address in the 'email' field). I have several php files that do everything except I cant get it to email to the address in the email field and I cant see where I'm going wrong. I am NOT very php literate and these files were created for me although I understand how they work mostly. Thanks! FridgeForm.html code: Code: [Select] <form onclick="return checkFields();" method="post" action="formsubmit.php" id="skopefridge" name="skopefridge" enctype="multipart/form-data"> <p align="right" class="style1 style2"><img src="skope_logo.png" width="235" height="38" border="0">JOB SHEET</p> <table BORDER=0 RULES=NONE FRAME=BOX cellspacing="2" cellpadding="7"> <tr> <td colspan="2"><strong>Request ID</strong> <input name="requestid" type="text" class="fieldwidth" id="firstname" maxlength="50" readonly style="background-color:#CCC"> </label> <strong>Operator Name</strong> <input name="operator" type="text" id="operator" size="20" maxlength="80"></td> <td colspan="3"><strong>Date & Time: </strong> <script type="text/javascript" src="time.js"></script></td> </tr> <tr> <td colspan="5"><strong>CALLERS DETAILS</strong></td> </tr> <tr> <td>Name</td> <td><input name="name" type="text" size="50" tabindex=1></td> <td>Night Phone</td> <td colspan="2"><input name="nightph" type="text" size="50" tabindex=5></td> </tr> <tr> <td>Street</td> <td><input name="street" type="text" size="50" tabindex=2></td> <td>Day Phone </td> <td colspan="2"><input name="dayph" type="text" size="50" tabindex=6></td> </tr> <tr> <td>Suburb</td> <td><input name="suburb" type="text" size="50" tabindex=3></td> <td>Mobile</td> <td colspan="2"><input name="mobile" type="text" size="50" tabindex=7></td> </tr> <tr> <td>City</td> <td><select name="selectcity" size="1" tabindex=4> <option value="Alexandra">Alexandra</option> <option value="Ashburton">Ashburton</option> <option value="Auckland">Auckland</option> <option value="Blenheim">Blenheim</option> <option value="Canterbury">Canterbury</option> <option value="Cromwell">Cromwell</option> <option value="Dannevirke">Dannevirke</option> <option value="Dargaville">Dargaville</option> <option value="Dunedin">Dunedin</option> <option value="Fiordland">Fiordland</option> <option value="Gisborne">Gisborne</option> <option value="Gore c/o Invercargill">Gore c/o Invercargill</option> <option value="Greymouth">Greymouth</option> <option value="Hamilton">Hamilton</option> <option value="Hastings">Hastings</option> <option value="Invercargill">Invercargill</option> <option value="Kerikeri">Kerikeri</option> <option value="Masterton">Masterton</option> <option value="Napier">Napier</option> <option value="Nelson">Nelson</option> <option value="New Plymouth">New Plymouth</option> <option value="Oamaru">Oamaru</option> <option value="Palmerston North">Palmerston North</option> <option value="Queenstown">Queenstown</option> <option value="Ranfurly">Ranfurly</option> <option value="Rotorua">Rotorua</option> <option value="Taupo">Taupo</option> <option value="Tauranga/ mt maunganui">Tauranga/ mt maunganui</option> <option value="Timaru">Timaru</option> <option value="Wanaka">Wanaka</option> <option value="Wanganui">Wanganui</option> <option value="Wellington">Wellington</option> <option value="Westport">Westport</option> <option value="Whakatane">Whakatane</option> <option value="Whangerei">Whangerei</option> <option value="test">test</option> <option value="test2">test2</option> </select></td> <td>Company</td> <td colspan="2"><input name="company" type="text" size="50" id="company" tabindex=8></td> </tr> <tr> <td colspan="5"><strong>PRODUCT DETAILS</strong></td> </tr> <tr> <td>Model</td> <td><input name="model" type="text" size="50" tabindex=9></td> <td>Purchased From </td> <td colspan="2"><input name="purchfrom" type="text" size="50" tabindex=11></td> </tr> <tr> <td>Serial No</td> <td><input name="serial" type="text" size="50" tabindex=10></td> <td>Date Purchased </td> <td colspan="2"><input name="datepurch" type="text" size="50" tabindex=12></td> </tr> <tr> <td> </td> <td> </td> <td>Proof Of Purchase? </td> <td colspan="2"><input name="proofpurch" type="text" size="50" tabindex=13></td> </tr> <tr> <td>Room Heater Installed In </td> <td colspan="4"><input name="installed" type="text" size="50" tabindex=14></td> </tr> <tr> <td>Heater Problem </td> <td colspan="4"><input name="problem" type="text" size="50" tabindex=15></td> </tr> <tr> <td colspan="5" align="center"><span class="style4">FOR ANY PROBLEMS/ENQUIRIES PLEASE CONTACT SKOPE INDUSTRIES PH:0800 947 5673</span> </td> </tr> <tr> <td colspan="5" align="center"><hr> <strong>Contact Belinda at Skope Services if the complete heater needs to be replaced. | Replaced parts are to be kept for 3 months. <br> <font color="#FF0000">This form is automatically emailed to the contractor associated with the city you choose above. The contractors details are below (for the chosen city) if you need to contact them)</font></strong> </td> </tr> </table> <table border="0" cellspacing="4" cellpadding="4"> <tr> <td>Contractor</td> <td style="display:none;">City</td> <td>Address</td> <td>Phone</td> <td>Fax</td> <td>Email</td> </tr> <tr> <td><input type="text" name="contractor" id="contractor" readonly style="background-color:#CCC"></td> <td style="display:none;"><input type="text" name="city" id="city" readonly style="background-color:#CCC"></td> <td><input type="text" name="address" id="address" readonly style="background-color:#CCC"></td> <td><input type="text" name="phone" id="phone" readonly style="background-color:#CCC"></td> <td><input type="text" name="fax" id="fax" readonly style="background-color:#CCC"></td> <td><input type="text" name="email" id="email" readonly style="background-color:#CCC"></td> </tr> </table> <p> <input type="submit" name="Submit" value="Submit" style="width:1000px; height:30px; "> </p> </form> formsubmit.php: <?php include ('../tools/maketable.php'); include ('../tools/processing.php'); $config = "skopeGlobal.php"; /****************************************************************/ /*FORM SUBMITTED DATA */ /****************************************************************/ // These are the fields that are posted from the form to be changed to suit the form // Make sure that there is one variable per form field or you may miss data $requestid = $_REQUEST["requestid"]; $operator = $_REQUEST["operator"]; $name = $_REQUEST["name"]; $street = $_REQUEST["street"]; $suburb = $_REQUEST["suburb"]; $selectcity = $_REQUEST["selectcity"]; $nightph = $_REQUEST["nightph"]; $dayph = $_REQUEST["dayph"]; $mobile = $_REQUEST["mobile"]; $company = $_REQUEST["company"]; $model = $_REQUEST["model"]; $serial = $_REQUEST["serial"]; $purchfrom = $_REQUEST["purchfrom"]; $datepurch = $_REQUEST["datepurch"]; $proofpurch = $_REQUEST["proofpurch"]; $installed = $_REQUEST["installed"]; $problem = $_REQUEST["problem"]; $email = $_REQUEST["email"]; $callerInfo = "Request ID=".$requestid."; Operator=".$operator."; Name=".$name."; Street=".$street."; Suburb=".$suburb."; City=".$selectcity."; Night Phone=".$nightph."; Day Phone=".$dayph."; Mobile Phone=".$mobile."; Company Name=".$company."; Model=".$model."; Serial No=".$serial."; Purchased From=".$purchfrom."; Date Purchased=".$datepurch."; Proof of Purchase=".$proofpurch."; Room Installed In=".$installed."; Product Problem=".$problem."; Emailed To=".$email; $display .= makeTable("Call Details",$callerInfo,1); processData($config,$display,$callerInfo); ?> skopeGlobal.php: <?php $title = "Skope Fridge Form"; //TODO: The title should be changed to a significant title $stylesheet = "http://www.thecallcentre.co.nz/css/submittedstyling.css"; // TODO: This Has to be changed to a stylesheet for the site // this must be a url or email will not style correctly $logo = "http://www.thecallcentre.co.nz/other/tcclogo.jpg"; $fileName="Skope-FridgeFormResults.xls"; $emailTo= $_REQUEST["email"]; $emailFrom="info@thecallcentre.co.nz"; $redirect="Thankyou.html"; ?> There are also other processing files but I'm not sure if you need to see their code or not. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=319994.0 Hi, This is the code I made to show the problem: $useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729)"; $timeout = 10 ; $cookie = tempnam ("/tmp", "CURLCOOKIE"); $post = array('_method'=>"put", 'authenticity_token'=>' zcvcxfsdfvxcv', 'profile_image[a]'=>"@Girl-Next-Door-movie-f01.jpg" ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_URL, "http://localhost/test.php"); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt( $ch, CURLOPT_ENCODING, "" ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_AUTOREFERER, true ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $html = curl_exec($ch); curl_close($ch); Now this link used above: http://localhost/test.php has this code: print_r($_POST); print_r($_FILES); It simply prints whats in post and files. So the above code displays this on screen: Code: [Select] Array ( [_method] => put [authenticity_token] => zcvcxfsdfvxcv ) Array ( [profile_image] => Array ( [name] => Array ( [a] => Girl-Next-Door-movie-f01.jpg ) [type] => Array ( [a] => image/jpeg ) [tmp_name] => Array ( [a] => /tmp/phppLJPQV ) [error] => Array ( [a] => 0 ) [size] => Array ( [a] => 55377 ) ) ) but we need to modify the code so that it should display this: Code: [Select] Array ( [_method] => put [authenticity_token] => zcvcxfsdfvxcv ) Array ( [profile_image[a]] => Array ( [name] => Girl-Next-Door-movie-f01.jpg [type] => image/jpeg [tmp_name] => /tmp/phppLJPQV [error] => 0 [size] => 55377 ) ) Meaning, it is taking this(profile_image[a]) as an array when we are defining $post because that's how curl recognizes that we want to upload only a file or an array of files on server by http post. So, basically the problem is the name of the input field that is defined as an array (profile_image[a]) on the web page that we are trying to mock. If this(profile_image[a]) was this (profile_image_a)(without []) on that webpage, then it would not have been a problem. So, if you understand, this is basically a syntax problem. I do not know how stop curl from reading 'profile_image[a]' as an array here 'profile_image[a]'=>"@Girl-Next-Door-movie-f01.jpg. I need curl to read 'profile_image[a]' as an string and not array. I have to use [], otherwise I will not be able to mock the webpage as the name will change. It will give error. I hope I explained the problem and also gave you a way to test if you have a solution. Again, if your code starts displaying this: Code: [Select] Array ( [_method] => put [authenticity_token] => zcvcxfsdfvxcv ) Array ( [profile_image[a]] => Array ( [name] => Girl-Next-Door-movie-f01.jpg [type] => image/jpeg [tmp_name] => /tmp/phppLJPQV [error] => 0 [size] => 55377 ) ) ,then we have a solution. Thanks for helping in advance. Regards, Manoj hidden input field type doesnt display the full value i get from table, say if it is a first name and last name i get only the first name. here is my input field echo "<input type=hidden name=proid value=$result_row[project_id]></include>"; echo "<input type=text value=$result_row[project_name] readonly></include>"; my sql query returns the full name but when i input into the text field it returns an incomplete project name like say if it is fans of soccer, i just get the value "fans" in my display..... I have a search function in php where the text characters are matched to characters in a tables field--- works perfectly.... I need to make the input box have a droplist of words from database, this is also easy for me to do. the problem here is there is no definitive value! the options list always outputs a blank in the url--- its supposed to search a matching value and then output the matching value to url... Here is the droplist code: $output['RATESTITLE']='<input class="inputbox" type="text" size="24px" name="ratestitle" value="'.$sch->filter['ratestitle'].'" onfocus="if (this.value ==\''.$output['LANGUAGE_SEARCH_RATESTITLE'].'\') {this.value = \'\'}" />'; this outputs a input text box--- i want to have a droplist of options to populate this text box... If you must know this is the third day im at it... Hi i have this edit form that allows user to mofy data but the problems on the text box is that it deletes the rest of the data after the space from the first word i tried to increase the size of the varChars on mysql but did no work why it happens how can i stop from happening?? this the form input <input type="text" name="name" id="name" class='text_box' value="<?php echo $_GET['name'];?>"/> I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> Hi As i am a newbie, i finally been able to upload and resize an image, but i need to rename the files to random numbers, i have found a code but i dont know where i should have to embed it in my php can u please tell me where and how? this is my php if (isset($_POST['register']) && $_POST['register']) { $update = mysql_query("UPDATE agents SET credit= credit-1 WHERE username='$username'"); //image1 $nameone=$_FILES['myfileone']['name']; if ($nameone) { $dst_filename = resize_upload_image($_FILES['myfileone'], "images/"); if ($dst_filename !== false) { extract($dst_filename); $image1 = mysql_query ("UPDATE img SET image1='$img_filename', thumb1='$thumb_filename'"); } } function resize_image($srcfilename, $dstfilename, $new_width, $new_height) { $ext = strtoupper(pathinfo($srcfilename, PATHINFO_EXTENSION)); // JPEG image if(is_file($srcfilename) && ($ext == "JPG" OR $ext == "JPEG")) { // Get src dimensions list($width, $height) = getimagesize($srcfilename); // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($srcfilename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagejpeg($image_p, $dstfilename, 100); return TRUE; } // PNG image elseif(is_file($srcfilename) && $ext == "PNG") { // Get src dimensions list($width, $height) = getimagesize($srcfilename); // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefrompng($srcfilename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagepng($image_p, $dstfilename, 0); return TRUE; } return false; } function resize_upload_image($file, $path) { global $standard_width, $standard_height; global $thumb_width, $thumb_height; $img_name= $file['name']; $tmp_name= $file['tmp_name']; if ($img_name) { if (substr($path, strlen($path)-1) != "/") { $path .= "/"; } $original_img_name = $path."tmp-".$img_name; move_uploaded_file($tmp_name, $original_img_name); $img_location = $path.$img_name; $thumb_location = $path."thumb-".$img_name; if (resize_image($original_img_name, $img_location, $standard_width, $standard_height) === FALSE) { unlink($original_img_name); return false; } if (resize_image($original_img_name, $thumb_location, $thumb_width, $thumb_height) === FALSE) { unlink($original_img_name); return false; } unlink($original_img_name); return array("img_filename"=>$img_location, "thumb_filename"=>$thumb_location); } return false; } sp this is a time id which could be added $image_name=time().'.'.$extension; $filename = "img/". $image_name; $filename1 = "img/small_". $image_name; Ok, so i've managed to upload images, but now i'm trying to rename them to avoid replacement and i've done something like this: mysql_query( "INSERT INTO `softmarket`.`internet_securitate` (`internet_securitateID`, `nume_produs`, `descriere`, `versiune`,`poza`, `pret`, `disponibilitate_produs`) VALUES ('', '$_POST[titlu]', '$_POST[descriere]', '$_POST[versiune]', '$foto', '$_POST[pret]', '$_POST[disponibilitate]');"); Code: [Select] function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['foto']['name']) ; $ran2 = $foto."."; $target = "../images/"; $target = $target . $ran2.$ext; while (file_exists($target)) { $ran2 = 'copyof'.$ran2; $target = $target . $ran2.$ext; } if(move_uploaded_file($_FILES['foto']['tmp_name'], $target)) { echo "The file has been uploaded as ".$ran2.$ext; } else { echo "Sorry, there was a problem uploading your file."; } header('Location: succes.php'); but it renames them in a wierd way...what is wrong? Does anyone know how i can rename a PDF file name using PHP? What i have right now is a form where the user can upload a pdf file, however i want to be able to to rename the file and save it to the server. |