title of uploaded mp3 in form files [duplicate] - php

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Reading a File's Metadata
i have this form where i am uploading mp3 files but i want users to upload music and all details like author,title etc of mp3 should automatically filled in form field.i am using php and want any php/javascript method which can find out the name of the file from local machine and put that name in my form title field
my form is given below. i dont want users to enter title,author etc
<form enctype="multipart/form-data" method="post" action="http://youshare.ca/music/writestorypost"><p><span class="form_label">Name of the song</span><input type="text" value="" name="title" style="width:400px" class="inputText required"></p><p><span class="form_label">Description</span>
<textarea class="rich" style="width:580px" rows="18" name="form_content"></textarea>
</p><p><span class="form_label">Tags</span>
<input type="text" value="" style="width:300px" name="tags" class="inputText">
<span>Multiple tags should be Separated with commas(,)</span>
</p>
<p><label>Upload</label><input type="file" name="song">
<span>Only mp3 is accepted</span></p>
<p><label>Music source</label>
<input type="radio" checked="1" value="own" name="musicsource">My own
<input type="radio" value="others" name="musicsource">From another musician
</p>
<div style="display:none" id="ms_others">
<p><label>Musician name</label><input name="musician"></p>
</div>
<div id="ms_own">
<p></p>
</div>
<p><label>Picture (Optional)</label><input type="file" name="picture">
<span>A picture about the song or the musician</span></p>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("input[value='own']").click(
function() {
$("#ms_others").hide();
$("#ms_own").fadeIn();
}
);
$("input[value='others']").click(
function() {
$("#ms_own").hide();
$("#ms_others").fadeIn();
}
);
})
</script><p><input type="submit" value="Submit" class="button"></p><input type="hidden" value="935" name="page_id"></form>

You will need to populate your MP3's details after the file is uploaded, unless they manually type in all information.
On the PHP side, you can install the following: PHP ID3
There are examples there on how to read ID3 tags from files.

Related

Reopen toggle after form submit

I am still working on my school project, which is almost finished.
With your help, I successfully created a working system that allows users to write, edit and delete data to/from the database.
The only problem I have right now us "user-friendly form." I managed to create auto-focus, insert correct values on edit so the user can see what was previously written in that field, etc.
I have my forms hidden with jquery. When a user clicks add, the form slides in. What I need to achieve is: "when a user clicks submit and the page refreshes and adds the element to the database, the form should appear again so users can add data faster."
Here is my code.
$(document).ready(function() {
$('#x').click(function() {
$('.y').toggle("slide");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="x">Click</div>
<div class="y" style="display: none;">
<div class="container">
<form action="insertzunanja.php" method="POST" id="x">
<input type="hidden" name="narocilo" value="0.1412312">
<input type="hidden" name="id" value="id-1">
<input type="text" name="dolzina" style="width:49%;" placeholder="Dolzina (v cm)">
<input type="text" name="sirina" style="width:49%;" placeholder="Sirina (v cm)">
<input type="text" name="kolicina" value="1" style="width:49%;" placeholder="Kolicina">
<input type="text" name="opombe" style="width:49%;" placeholder="Opombe">
<input type="submit" value="Send">
</form>
</div>
</div>
Thanks and best regards.
You can use AJAX call to send the data to php file instead of form action. According to your code you will have something like this:
<div id="x">Dodaj</div>
<div class="y" style="display: none;">
<div class="container">
<input type="hidden" name="narocilo" value="<?php echo $randomNum; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="text" name="dolzina" style="width:49%;" placeholder="Dolzina (v cm)">
<input type="text" name="sirina" style="width:49%;" placeholder="sirina (v cm)">
<input type="text" name="kolicina" value="1" style="width:49%;" placeholder="Kolicina">
<input type="text" name="opombe" style="width:49%;" placeholder="Opombe">
<input id="sub" type="submit" value="Send">
</div>
</div>
$(document).ready(function(){
$('#x').click(function() {
$('.y').toggle("slide");
});
});
$("sub").click(function(){
$.post("insertzunanja.php",
{
dolzina: $("input[name=dolzina]"),
sirin: $("input[name=sirina]")
},
function(){
$("input[name=dolzina]").val("");
$("input[name=sirina]").val("");
if($('.y').is( ":hidden" )) {
$('.y').toggle("slide");
}
});
});
Basically, when you click on button you call php with AJAX POST request passing two values dolzina and sirin retrieved by the html code(note: you have more values to pass so change it accordingly) to php file. Jquery deletes the values of the input fields and check if input fields are shown. If not the inputs fields are shown.
If you are using PHP to process the form submission and generate the code in your question, and you always want the form to be displayed after submission, you can do this:
At the PHP code identify submission (e.g. isset($_REQUEST['id']) ).
[if #1 is true] On generating jQuery code, add $('.y').show(); within the ready function (but separated from the existing click function).
Example:
<?php
// your existing code...
?>
$(document).ready(function() {
<?= ( isset($_REQUEST['id']) ? '$(".y").show();' : '' ); ?>
$('#x').click(function() {
$('.y').toggle("slide");
});
});
<?php
// your existing code...
?>

Browsed file name is not getting displayed in textbox

<input title="Browse" type="file" name="file" onchange="this.parentNode.nextSibling.value = this.value.split('\\').pop().split('/').pop()">
Browse
From the above code i am uploading file and uploaded file is working fine but when i click upload button the current browsed file name is not getting displayed in the text box which i provided.
Since you'll display the file-name in a separate text-box and you won't use the default filename display. It's better to create a button and have it call the file-upload using onclick. After that you can get the file-name and assign it to the text-box you created using the javascript below.
javascript:
var filename;
document.getElementById('fileInput').onchange = function () {
filename = this.value.split(String.fromCharCode(92));
document.getElementById("fileText").value = filename[filename.length-1];
};
HTML:
<label for="file" class="input input-file">
<input type="text" id="fileText" placeholder="Upload Students file" readonly="" />
<input type="file" id="fileInput" style="display: none;" />
<input type="button" value="Choose File" onclick="document.getElementById('fileInput').click();" />
</label>
I've made a quick demo for you here: http://jsfiddle.net/x9L8etfg/
Hope this helps.
you have to parse to the parent of text node, then only you can set the value.
use this:
onchange="this.parentNode.parentNode.childNodes[1].value = this.value.split('\\').pop().split('/').pop()"

jQuery stop working after 2nd reply in a post [duplicate]

This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
Closed 8 years ago.
I have php comment system like Facebook where user can post comment and reply. when I make 2 reply in a comment one after one then I cannot make 3rd reply in same comment. Also here cannot work emoticons slide and upload toggle. But can reply others comments. I cannot understand this type of jQuery behaviour!!! I also can't understand, can php create this type of problem?
For emoticons display yet I create review window behind textarea And make my textarea transparent. So here I used jQuery bind(). All comment and reply submit by AJAX.
When i going to reply 3rd time Its not work in same comment. But after refresh its work for more 2 reply only.
Here is some related jQuery:
$('.maintbox').on('keyup',function() {
$(this).css('height','auto');
$(this).css('height',Math.max(this.scrollHeight)+'px');
});
$('.replycom').livequery("click",function() {
var VID = $(this).attr('id').replace('replycom','');
$("#parent_id").attr("value", VID);
$("#replycom"+VID).bind("keyup", function() {
$("#replycom"+VID).html($(this).val());
$(".review"+VID).html(smilyMe($("#replycom"+VID).val()));
});
return false;
});
$('.showhide_emobox').livequery("click",function(){
var EID = $(this).attr("id");
$("#emobox"+EID).slideToggle();
});
$(".embtno").livequery("click",function(event){
var emotiText = $(event.target).attr("alt");
var EID = $(this).attr('id').replace('','');
var prevMsg = $("#replycom"+EID).val();
$("#replycom"+EID).val(prevMsg + emotiText);
$(".review"+EID).html(smilyMe($("#replycom"+EID).val()));
$('#emobox'+EID).fadeToggle();
});
my form:
echo'<div class="replyform"><ul>
<form action="" method="post" class="repfrm'.$rows['id'].'" id="prepfrm">
<fieldset id="cmntfs">
<input type="hidden" name="username" id="author" value="'.$_SESSION['username'].'"/>
<input type="hidden" name="url" id="url" value="" />
<div class="maintbox">
<div class="chat">
<div class="review'.$rows['id'].'" id="review"></div>
<textarea name="replycom" id="replycom'.$rows['id'].'" class="replycom" placeholder="Type your comment ..."></textarea>
</div>
<div align="right"><img src="images/envlop.png" width="25" alt="" class="uploadReply" id="'.$rows['id'].'" style="padding:2px;cursor:pointer;" />
<div class="em">
<img src="images/smile.png" id="'.$rows['id'].'" class="showhide_emobox"/>
<div id="emobox'.$rows['id'].'" class="emobox">
<img src="smilies/smile.gif" alt=":)" class="embtno" id="'.$rows['id'].'" />
<img src="smilies/sad.gif" alt=":(" class="embtno" id="'.$rows['id'].'" />
<img src="smilies/biggrin.gif" alt=":-D" class="embtno" id="'.$rows['id'].'" />
</div>
</div>
</div>
<input type="hidden" name="parent_id" id="parent_id" value="'.$rows['id'].'" />
<input type="hidden" name="tutid" id="tutid" value="'.$tutid.'" />
</form>
// Image upload system here
</div>
<button type="submit" name="submit" value="" id="repl'.$rows['id'].'" class="replyfrm">Post Reply</button>
</fieldset>
</ul></div>';
You are using:
$("#replycom"+VID)
There can be only one id of the same name. Your first reply gets unique id, your second reply gets duplicate, and your code stops to work.

jQuery submit only subpart of form (files-input)

I have a Form with some fields:
<form action="xyz.php" method="post" enctype="multipart/form-data">
<input type="text" placeholder="First name" name="firstname">
...
<input type="file" name="logo">
...
<input type="submit" name="submit">
</form>
The image should be uploaded immediately to img_upload.php. In this file i need the $_FILES array.
My img_upload.php script uploads the image, do some things with the image (resize, ...) and give me the URL to the image. After this, the image should be displayed in the form.
Is there any chance to upload the image (send $_FILES array to another file) without submiting the whole form?
<input type="file" name="logo" onchange="uploadThisFile(this)" >
function uploadThisFile(file) {
/* launch an ajax request to img_upload.php and pass file details via POST */
}

'Upload' form to grab complete location of file?

I've created a HTML and PHP form to pretty much just input data into a MySQL table.
I've got a file upload field, but it doesn't upload a file. I don't want it to upload anything to the server, all I want is for it to grab the location of the file selected and input that into the database.
It works perfectly fine on Internet Explorer, but doesn't work on any other browser, I assume it's because of security issues it imposes.
My input code:
<input type="file" id="filename" name="filename" />
And of course when the form is submitted some PHP code runs through to insert the data into the database. I've tried JavaScript to copy value of that field to to another field but again because of security issues that doesn't work.
Does anyone know of a way I can do this in JavaScript? Or even Flash? To be honest, anything similar to these would do, just something that works in browsers other than IE.
Thanks.
EDIT -
Here's my code:
<?php
if (isset($_POST['submit'])) {
$name = addslashes(htmlentities($_POST['name']));
$filename = addslashes(htmlentities($_POST['filename']));
if (#mysql_query("INSERT INTO movies SET
name='$name',
doc_filename='$filename'")) {
echo '<p>Movie added.</p><p>Manage movies.</p>';
} else {
echo '<strong>Error:</strong> '.mysql_error().'';
}
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="newspost" enctype="multipart/form-data">
<div class="form-row">
<label for="fm_title">Movie file path: </label><br />
<input type="file" id="filename" name="filename" />
</div><br />
<div class="form-row">
<label for="fm_title">Movie name: </label><br />
<input type="text" class="input-width" name="name" value="<?php if (!empty($_POST['name'])) { echo $_POST['name']; } ?>" />
</div>
<div class="form-row">
<input type="submit" name="submit" value="Submit" />
</div>
</form>
<?php
}
?>
all I want is for it to grab the location of the file selected and input that into the database.
This is no longer possible using HTML - for security reasons, the location of the selected file is not accessible in the file input's DOM element anymore. Most browsers use C:\Fakepath\ instead.
You might be able to get hold of this information using a Flash or Java based uploader (edit: see e.g. this page in the AS3 manual) SWFUpload's API could be worth a look. It could be that you need to build your own Flash or Java solution for this, though.
how you are posting the data of the form? I am not able to see any way of form post. No Submit button or onclick or onchange event of javascript? and also how you suppose this line to give output
<input type="text" class="input-width" name="name" value="<?php if (!empty($_POST['name'])) { echo $_POST['name']; } ?>" />
as its already in else part of the line
if (isset($_POST['submit']))

Categories