Need help guys about this form, saving data to database is good my problem is I can't save files in database don't know what to change do I need to add var file or add &lt;form id=''&gt; really don't know what todo and I don't have any idea on how to save files using ajax form and I'm not really good in jQuery/ajax. please help.  &lt;textarea class='message' cols ='30' rows ='5' id = 'message'&gt;&lt;/textarea&gt; &lt;form method="post" enctype="multipart/form-data"&gt; &lt;label for="fileToUpload"&gt;&lt;img src="img icon.png" title="Attach Image"&gt;  &lt;/label&gt; &lt;input id="fileToUpload" name="fileToUpload" type="file" onchange="document.getElementById('file').value = this.value.split('\\').pop().split('/').pop()"/&gt; &lt;input type="text" name="file" id="file" class="file"&gt; &lt;button class="submit"  id="submit" name="submit" &gt;Comment&lt;/button&gt; &lt;/form&gt;  &lt;script&gt;     $('.submit').click(function(){         var name = '&lt;?php echo $row['name'];?&gt;';         var message = $('.message').val();         if(message.length&gt;1){         $.ajax({             url:'upload.php?id=&lt;?php echo $id;?&gt;',             data:'name='+name+'&amp;message='+message,             type:'post',             success:function()             {                 $('.message').val('');                 listComments();                 alert('Post Message');             }         })         }else{              alert('PLEASE DO RIGHT A MESSAGE BEFORE SENDING');              }     }) &lt;/script&gt;   upload.php  &lt;?php $id = $_GET['id']; $name = $_SESSION['u_uname']; $file = $_FILES['fileToUpload']['name']; $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $message = mysqli_real_escape_string($conn,$_POST['message']); $daterep = date('Y-m-d H:i:s');  $qry = "INSERT INTO forum_answer (topicid,name,message,daterep,file) VALUES  ('$id','$name','$message','$daterep','$target_file')"; $log = mysqli_query($conn,$qry);  move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_dir.$file); ?&gt;
7478
I would like to upload a file asynchronously with jQuery.     $(document).ready(function () {     $("#uploadbutton").click(function () {         var filename = $("#file").val();          $.ajax({             type: "POST",             url: "addFile.do",             enctype: 'multipart/form-data',             data: {                 file: filename             },             success: function () {                 alert("Data Uploaded: ");             }         });     }); }); &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;&lt;/script&gt; &lt;span&gt;File&lt;/span&gt; &lt;input type="file" id="file" name="file" size="10"/&gt; &lt;input id="uploadbutton" type="button" value="Upload"/&gt;     Instead of the file being uploaded, I am only getting the filename. What can I do to fix this problem?
52925
I built a custom form that saves the data to multiple lists with on click; it works pretty well for its intended use (keeping the data related). Thing is I am totally new at jQuery and SPServices, but am learning.   I would like to know if SPService/jQuery will allow me to use the aspx control to upload a single document to a library? I have seen plugins out there for multiple file uploads so I assume this is possible, but all of these seem way to much for what I am trying to do, and I would like to learn how to do it.  Does anyone know if this is possible? Could provide simple example or explanation or reference?  Appreciate it as always!
70560
I'm writing an application that allows users to upload images onto the server. I expect about 20 images per day all jpeg and probably not edited/resized. (This is another question, how to resize the images on the server side before storing. Maybe someone can please drop a .NET resource for that in the comment or so).  I wonder now what the best place for storing uploaded images is.   Store the images as a file in the file system and create a record in a table with the exact path to that image. Or, store the image itself in a table using an "image" or "binary data" data type of the database server.   I see advantages and disadvantages in both.  I like a) because I can easily relocate the files and just have to change the table entry. On the other hand I don't like storing business data on the web server and I don't really want to connect the web server to any other datasource that holds business data (for security reasons)  I like b) because all the information is in one place and easily accessible by a query. On the other hand the database will get very big very soon. Outsourcing that data could be more difficult.
113384
Drag and drop or click here to upload your image area is not working if error message is shown. If I try to add an image into a post and provide a wrong URL(not intentionally) which is not in the format recognized by SE sites it displays me,     Failed to upload image; the format is not supported | Close   This is okay. But the option,     Drag and drop or click here to upload your image (max 2 MiB)   shown above this error message is not responding on-mouse-click unless I click the Close to clear the error message shown below this message.     (i.e.) The local file upload window is not opening. However, the drag and drop functionality works fine even if the error message is shown. So the upload window works partially.   Expected behavior:  When I click the "Click here to upload your image", it should always open me the file upload window and clear any error messages shown below.  Tested on:  Firefox 39 and Chrome 44 in Windows 7 PC
89834
I have:  &lt;?php  $file=fopen(date("Y-m-d").".txt","r+") or exit("Unable to open file!");  if ($_POST["lastname"] &lt;&gt; "") {    fwrite($file,$_POST["lastname"]."\n"); }  fclose($file);  ?&gt;   but it overwrites the beginning of the file.  How do I make it insert?
105831
Drupal 7. Custom module. I have a content type 'RFI' with a handful of fields I created with Drupal UI. I want a user to: fill out a form &amp; click submit while drupal: saves fields to database, creates a new node of 'RFI' and populates the fields of the node with the content provided by the form's corresponding fields.  From what I understand:  Build a form with fields (taking from the 'DBTNG examples' module just for clarity):  function rfi_build_form($form, &amp;$form_state) { $form = array();  $form['add'] = array( '#type'  =&gt; 'fieldset', '#title' =&gt; t('Add a person entry'), ); $form['add']['name'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Name'), '#size'  =&gt; 15, ); $form['add']['surname'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Surname'), '#size'  =&gt; 15, ); $form['add']['age'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Age'), '#size'  =&gt; 5, '#description' =&gt; t("Values greater than 127 will cause an exception. Try it - it's a    great example why exception handling is needed with DTBNG."), ); $form['add']['submit'] = array( '#type'  =&gt; 'submit', '#value' =&gt; t('Add'), ); return $form; }   Here the form fields are saved to database with database API.  function rfi_build_submit($form, &amp;$form_state) { global $user;  // Save the submitted entry. $entry = array( 'name'    =&gt; $form_state['values']['name'], 'surname' =&gt; $form_state['values']['surname'], 'age'     =&gt; $form_state['values']['age'], 'uid'     =&gt; $user-&gt;uid, ); $return = dbtng_example_entry_insert($entry); if ($return) { drupal_set_message(t("Created entry @entry", array('@entry' =&gt; print_r($entry, TRUE)))); } }   Now here is how I know how to create a node of RFI type. How do I take the values of the fields above [name], [surname], [age] and have them related to corresponding fields in my content type?  function rfi_build_type($form, &amp;$form_state){ $node = new stdClass(); $node-&gt;type = 'rfi'; $node-&gt;name = ''; $node-&gt;surname = ''; $node-&gt;age = ''; $node-&gt;language = 'en'; $node-&gt;uid = 1; node_save($node); }   I was thinking that since the fields have been saved already, that I could use a database query to get these values, but intuition tells me I'm overlooking something.  Thank you!
116031
I'm trying to write some PHP to upload a file to a folder on my webserver. Here's what I have:  &lt;?php     if ( !empty($_FILES['file']['tmp_name']) ) {         move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']);         header('Location: http://www.mywebsite.com/dump/');         exit;     } ?&gt;  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt; &lt;html&gt;     &lt;head&gt;         &lt;title&gt;Dump Upload&lt;/title&gt;     &lt;/head&gt;     &lt;body&gt;         &lt;h1&gt;Upload a File&lt;/h1&gt;         &lt;form action="upload.php" enctype="multipart/form-data" method="post"&gt;             &lt;input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /&gt;             Select the File:&lt;br /&gt;&lt;input type="file" name="file" /&gt;&lt;br /&gt;             &lt;input type="submit" value="Upload" /&gt;         &lt;/form&gt;     &lt;/body&gt; &lt;/html&gt;   I'm getting these errors:     Warning: move_uploaded_file(./test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3      Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\phpA30E.tmp' to './test.txt' in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3      Warning: Cannot modify header information - headers already sent by (output started at E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php:3) in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 4   PHP version 4.4.7 Running IIS on a Windows box. This particular file/folder has 777 permissions.  Any ideas?
108591
I have a form which allows the user to create extra "rows" using JQuery (using .clone) so that they can decide how many of the same information they need to submit. My issue is that I cannot work out how to access these form items within my controller.  the form that is being submitted may look like this  &lt;input type="text" name="Amount" id="Amount"&gt;    &lt;select name="Item"&gt;        &lt;option value="1"&gt;Item 1"&lt;/option&gt;        &lt;option value="2"&gt;Item 2"&lt;/option&gt;        &lt;option value="3"&gt;Item 3"&lt;/option&gt;    &lt;/select&gt; &lt;input type="text" name="Amount" id="Amount"&gt;    &lt;select name="Item"&gt;        &lt;option value="1"&gt;Item 1"&lt;/option&gt;        &lt;option value="2"&gt;Item 2"&lt;/option&gt;        &lt;option value="3"&gt;Item 3"&lt;/option&gt;    &lt;/select&gt; &lt;input type="text" name="Amount" id="Amount"&gt;    &lt;select name="Item"&gt;        &lt;option value="1"&gt;Item 1"&lt;/option&gt;        &lt;option value="2"&gt;Item 2"&lt;/option&gt;        &lt;option value="3"&gt;Item 3"&lt;/option&gt;    &lt;/select&gt;   Basically, the block between input and the select could be repeated an infinite number of times. When I submit to the controller I am then using FormCollection form to access the form elements. from there I am unsure how I can access the items that have been submitted. I thought of using a for loop and then accessing them via something like form["Amount"][i] but obviously that is not going to work.  Am I going about this the right way and if so, does anyone have any suggestions about how this might work?  Thanks in advance.
26981
I searched all over this site and the web for a good and simple example of autocomplete using jQuery and ASP.NET. I wanted to expose the data used by autocomplete with a webservice (and will probably do that next). In the meantime, I got this working, but it seems a little hacky...  In my page I have a text box:  &lt;input id="txtSearch" type="text" /&gt;   I am using jQuery autocomplete, set up per their example:  &lt;link rel="stylesheet" href="js/jquery.autocomplete.css" type="text/css" /&gt; &lt;script type="text/javascript" src="js/jquery.bgiframe.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jquery.dimensions.pack.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/jquery.autocomplete.js"&gt;&lt;/script&gt;   Here is where it starts to get hacky... I call a page instead of a webservice:    &lt;script type="text/javascript"&gt;     $(document).ready(function(){         $("#txtSearch").autocomplete('autocompletetagdata.aspx');     });         &lt;/script&gt;   In the page I stripped out ALL of the html and just have this (otherwise, various HTML bits show up in the autocomplete dropdown):  &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="autocompletetagdata.aspx.cs" Inherits="autocompletetagdata" %&gt;   And in my autocompletetagdata.aspx, I am using SubSonic to query, format and return data from the database (one data item per line):  protected void Page_Load(object sender, EventArgs e) {     // Note the query strings passed by jquery autocomplete:     //QueryString: {q=a&amp;limit=150&amp;timestamp=1227198175320}      LookupTagCollection tags = Select.AllColumnsFrom&lt;LookupTag&gt;()         .Top(Request.QueryString["limit"])         .Where(LookupTag.Columns.TagDescription).Like(Request.QueryString["q"] + "%")         .OrderAsc(LookupTag.Columns.TagDescription)         .ExecuteAsCollection&lt;LookupTagCollection&gt;();      StringBuilder sb = new StringBuilder();      foreach (LookupTag tag in tags)     {         sb.Append(tag.TagDescription).Append("\n");     }      Response.Write(sb.ToString()); }   If you don't do a LIKE query, then it returns everything that contains a match for the character(s) you type -- e.g., typing "a" will include "Ask" and "Answer" as well as "March" and "Mega." I just wanted it to do a starts with match.  Anyway, it works and it's pretty easy to set up, but is there a better way?
112379
I have some use cases where I need to build a web form that includes a way for a site visitor to upload a file (jpeg, png, pdf types)  Any ideas on the best way to do this?
91776
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.   function check_my_login( $atts)     {          return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt;                &lt;div class="form-group"&gt;                     &lt;label for="description"&gt;Project Description&lt;/label&gt;                     &lt;textarea name="p_description" placeholder="Project Description" class="form-control"&gt;&lt;?php if (isset($_POST['p_description']) &amp;&amp; $_POST['p_description'] != '') echo $_POST['p_description'] ?&gt;&lt;/textarea&gt;                 &lt;/div&gt;                  &lt;div class="form-group"&gt;                     &lt;label&gt;Project Attachment&lt;/label&gt;                     &lt;input type="file" name="p_attachment"&gt;                 &lt;/div&gt; &lt;/form&gt;';     }     add_shortcode( 'kentaUser', 'check_my_login' );   Now use this shortcode inside the Post/page.   Like this    &lt;div class='manage_page'&gt;[kentaUser]&lt;/div&gt;  But my shortcode content display out side the div.Display upper side in post/page content.  &lt;div class='manage_page'&gt;&lt;/div&gt;    Any one short out this problem.
101504
I added this code but when I upload 1 image, then 4 images of 1 image are uploaded, what is happening IMAGES : Not proper working PDF file upload : work fine Doc file upload : work fine rvt file upload : not working Now I am trying to upload multiple files my HTML code is: &lt;input type=&quot;file&quot; name=&quot;my_file_upload[]&quot; id=&quot;my_file_upload[]&quot; multiple=&quot;multiple&quot;&gt;  Code &gt; file custom.php if ( $_FILES ) {  $files = $_FILES[&quot;my_file_upload&quot;];   foreach ($files['name'] as $key =&gt; $value) {                     if ($files['name'][$key]) {              $file = array(                  'name' =&gt; $files['name'][$key],                 'type' =&gt; $files['type'][$key],                  'tmp_name' =&gt; $files['tmp_name'][$key],                  'error' =&gt; $files['error'][$key],                 'size' =&gt; $files['size'][$key]             );              $_FILES = array (&quot;my_file_upload&quot; =&gt; $file);              foreach ($_FILES as $file =&gt; $array) {                               $newupload = my_handle_attachment($file,$pid);              }         }      }  }  Function.php File code function my_handle_attachment($file_handler,$post_id,$set_thu=false) { // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();   require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/image.php');  require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/file.php');  require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/media.php');   $attach_id = media_handle_upload( $file_handler, $post_id ); if ( is_numeric( $attach_id ) ) {   update_post_meta( $post_id, '_my_file_upload', $attach_id );  } return $attach_id; }
61965
My module provides a configuration form which allows to select a content type and on submit 2 new fields will be added to the selected content types.  I want to add these fields to the content types programmatically and I tried this using hook_entity_bundle_field_info but the fields don't get saved.  How can I save the fields? And how can I delete the fields (if the user changes the content type in the configuration form)?
92994
I have an HTML form - with PHP, I am sending the data of the form into a MySQL database. Some of the answers to the questions on the form have checkboxes. Obviously, the user does not have to tick all checkboxes for one question. I also want to make the other questions (including radio groups) optional.  However, if I submit the form with empty boxes, radio-groups etc, I received a long list of 'Undefined index' error messages for each of them.  How can I get around this? Thanks.
42040
When I right click anywhere I get an option to add a new file with a specified extension. I would like to add some custom files into this menu, so I can right click and create a new PHP file for instance.  How can I do this?
53910
I have a form where the user can input datetime and then I want to store it in the database. Here's my schema :     'start' => array(           'type' => 'varchar', 'mysql_type' => 'datetime',           'not null' => FALSE,         ),   The form :     $form['add']['start'] = array(         '#type' => 'datetime',   '#default_value' => $date,       );   When I hit submit button, it shows me :     db_insert failed. Message = SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value:...   What I got out of it was that the DateTime in Drupal is incompatible with MySQL's. Any suggestions or how should I process the value from the form so I can insert it into the db?  Alternatively, any way to convert DrupalDatetime into string?  (For what it's worth I also tried 'timestamp' as the MySQL type but it throws me the same error).
41405
Possible Duplicate:          I was wondering if there's any good reason to still use blob fields in a database. A couple of years ago I worked with a DB with a bunch of images in it, the DB was very slow and I couldn't see any good reason to keep the images inside the DB, so I got the images out and stored the filenames instead.  Was this a smart move? What would you do in my place?