Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This code would work fine without the use of javascript. But make sure to change the directory and the table name and fields on line "2" and "66" resp.</p> <p>We will create a hidden textarea which will create the datastring and we will get all the params using $_GET </p> <pre><code>&lt;script&gt; $("#update").click(function(e) { alert("update"); e.preventDefault(); var ttle = $("#title").val(); alert(ttle); var text = $("#prjdesc").val(); var vurl = $("#vurl").val(); var img = $("#file").val(); alert(vurl); var textareastring = $('#string').val(); var dataString = 'textareastring' = textareastring; $.ajax({ type:'POST', data:dataString, url:'insert.php?param='+text+'&amp;param1='+vurl+'&amp;param2='+ttle+'&amp;param3='+img', success:function(id) { alert(id); window.location ="another.php?id="+id;; } }); }); &lt;/script&gt; &lt;textarea id="string" style="display:none;"&gt;aa&lt;/textarea&gt; &lt;?php $name = $_GET['param3']; // The name.n ow replacing all the $file_name with $name $url = $_GET['param1']; $text = $_GET['param']; $title = $_GET['param2']; $upload_dir = $url; $num_files = 1; //the file size in bytes. $size_bytes =104857600; //51200 bytes = 50KB. //Extensions you want files uploaded limited to. $limitedext = array(".tif",".gif",".png",".jpeg",".jpg"); //check if the directory exists or not. if (!is_dir("$upload_dir")) { die ("Error: The directory &lt;b&gt;($upload_dir)&lt;/b&gt; doesn't exist. "); } //check if the directory is writable. if (!is_writeable("$upload_dir")){ die ("Error: The directory &lt;b&gt;($upload_dir)&lt;/b&gt; . "); } if (isset($_POST['upload_form'])){ echo "&lt;h3&gt;Upload results:&lt;/h3&gt;&lt;br&gt;"; //do a loop for uploading files based on ($num_files) number of files. for ($i = 1; $i &lt;= $num_files; $i++) { //define variables to hold the values. $new_file = $_FILES['file'.$i]; $name = $new_file['name']; //to remove spaces from file name we have to replace it with "_". $name = str_replace(' ', '_', $name); $file_tmp = $new_file['tmp_name']; $file_size = $new_file['size']; #-----------------------------------------------------------# # this code will check if the files was selected or not. # #-----------------------------------------------------------# if (!is_uploaded_file($file_tmp)) { //print error message and file number. echo "File: Not selected.&lt;br&gt;&lt;br&gt;"; }else{ #-----------------------------------------------------------# # this code will check file extension # #-----------------------------------------------------------# $ext = strrchr($name,'.'); if (!in_array(strtolower($ext),$limitedext)) { echo "File $i: ($name) Wrong file extension. &lt;br&gt;&lt;br&gt;"; }else{ #-----------------------------------------------------------# # this code will check file size is correct # #-----------------------------------------------------------# if ($file_size &gt; $size_bytes){ echo "File : ($name) Faild to upload. File must be no larger than &lt;b&gt;100 MB&lt;/b&gt; in size."; }else{ #-----------------------------------------------------------# # this code check if file is Already EXISTS. # #-----------------------------------------------------------# if(file_exists($upload_dir.$name)){ echo "File: ($name) already exists. &lt;br&gt;&lt;br&gt;"; }else{ #-------------------------------# # this function will upload the files. # #-------------------------------# if (move_uploaded_file($file_tmp,$upload_dir.$name)) { $sql = "INSERT INTO table_name(field1, field2) VALUES('$field1', '$field2');"; echo "File: ($name) has been uploaded successfully." . "&lt;img src='uploads/$name'/&gt;"; }else{ echo "File: Faild to upload. &lt;br&gt;&lt;br&gt;"; }#end of (move_uploaded_file). }#end of (file_exists). }#end of (file_size). }#end of (limitedext). }#end of (!is_uploaded_file). }#end of (for loop). # print back button. //////////////////////////////////////////////////////////////////////////////// //else if the form didn't submitted then show it. }else{ echo "&lt;form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form- data\"&gt;"; // show the file input field based on($num_files). for ($i = 1; $i &lt;= $num_files; $i++) { echo "&lt;b&gt;Image: &lt;/b&gt;&lt;input type=\"file\" size=\"70\" name=\"file". $i ."\" style=\"width:45%\"&gt;"; } echo " &lt;input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\"&gt; &lt;input type=\"submit\" name=\"upload_form\" value=\"Upload\"&gt; &lt;/form&gt;"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload