Upload mp3 file not working in codeigniter - file-upload

I am trying to upload mp3 file into folder using codeigniter V3.1.8 but i get error when i trying to upload any .mp3 file. I got "The filetype you are attempting to upload is not allowed." error.
Here is my controller, view code.
CommonController.php
public function uploadSong( $ref_id ) {
$status = $url = "";
$data['user_info'] = $this->data;
if ($status != "error") {
$config['upload_path'] = './assets/songs/';
$url = 'assets/songs/';
}
$config['allowed_types'] = 'mp3';
$config['max_size'] = 99999;
//$config['encrypt_name'] = TRUE;
//chmod('assets/', 0777);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file_name')) {
$status = 'error';
$msg = $this->upload->display_errors('', '');
echo $msg;
} else {
// Go ahead
}
}
upload.php
<?php echo form_open_multipart(base_url() . 'upload-song/'.$song[0]['id']);?>
<div class="form-group">
<label>Select Song</label>
<input type="file" name="file_name" size="20" required="true" />
</div>
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Upload" />
<?php echo form_close(); ?>
config/mimes.php
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
Same process do with images upload and its working fine but am not getting what's going wrong with mp3 upload. Any idea whats going wrong with my code ?
Thanks in Advance.

You just need to replace in config/mimes.php from,
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
to,
'mp3' => array('video/mp3', 'application/octet-stream', 'audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
Now it's working fine.

Related

How to use Apis to view lines in Xtream code 2.9.2?

How to view Lines from Xtream Code CMS?
I am using some APIs but not able view lines it always shows me 'Access Denied'.
How to allow API access? I have Xtream code 2.9.2 version.
I know To use APIs, we have to import our IP address into the whitelist from General Settings -> API Settings. It was an option in Xtream code 2.3.x but in later versions, they have changed things. And by default, they have disabled the access of APIs. There is no such type of option in the current version of Xtream code we have.
Any solution? How to allow API access in xtream code 2.9.2?
<?php
$panel_url = 'https://cms.xtream-codes.com/xxxx/'; //i am giving my cms xtream code panel link here
$username = "xxxx"; //i am giving my xtream code cms username here
$password = "xxxx"; //i am giving my xtream code cms password here
##############################################################################
$post_data = array( 'username' => $username, 'password' => $password );
$opts = array( 'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query( $post_data ) ) );
$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api.php?action=user&sub=info", false, $context ), true );
echo implode( ',', $api_result);
?>
Access denied
Pretty sure the $panel_url refers to the URL to your main server rather than your cms panel
My solution for checking active subscription info using xtream-codes V2 API
create an Index.php page for your form
<form class="form-inline" action="submit.php" method="post">
<div class="form-group">
<input type="text" class="form-control" id="username" placeholder="Enter Lines Username" name="username">
<input type="text" class="form-control" id="password" placeholder="Enter Lines Password" name="password">
<button type="submit" id="submit" class="btn btn-primary" name="submit">GET STREAM IDS</button>
</form>
Create submit.php and point your form action to it
<?php
$surname = $_POST['surname'];
$username = $_POST['username'];
$password = $_POST['password'];
$exp_date = date("d-m-Y",$json['user_info']["exp_date"]);
$json = json_decode(file_get_contents("http://<-YOUR DNS ->:<-YOUR PORT ->/panel_api.php?username=$username&password=$password"), true);
?>
<?php echo $json['user_info']["username"];?></a>
<?php echo $json['user_info']["password"];?></a>
<?php echo $json['user_info']["status"];?></a>
<?php echo $exp_date;?></a>
and create a line download button like this
DOWNLOAD PLAYLIST
The below code will generate a table of active channels and their TS numbers dependant to the entered line subscription packages
<table>
<thead>
<tr>
<th width="50%"><center>STREAM NAME</center></th>
<th width="50%"><center>STREAM TS NUMBER</center></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$json = json_decode(file_get_contents("http://<-YOUR DNS ->:<-YOUR PORT ->/player_api.php?username=$username&password=$password&action=get_live_streams"), true);
for ($x = 0; $x < count($json); $x++)
{ ?>
<td><center><strong><?php echo $json[$x]['name'];?></strong></center></td>
<td><center><strong><?php echo $json[$x]['stream_id'];?></strong></center></td>
</tr>
<?php } ?>
these may not be the best methods but they work and I actually use myself

asp.net MVC form POST working in Localhost but not working after publishing

HomeController.cs:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(LoginInfo login)
{
if (Request.Form["Submit"] != null)
{
string Username = login.Username;
string Password = login.Password;
ViewBag.Massage = "";
if (Username == "Admin" && Password == "123")
{
ViewBag.Massage = "Login Successfull";
return RedirectToAction("MSISDN","UnSub");
}
else
{
ViewBag.Massage = "Please Enter Valid Login Information";
}
}
return View();
}
Views/Home/Index.cshtml
<form name="myForm" action="/Home/Index" method="post">
<div align="center">
<div style="color:red">#ViewBag.Massage</div>
<br>
<label for="Username">Username:</label>
<input type="text" name="Username" id="Username">
<label for="Password">Password:</label>
<input type="password" name="Password" id="Password">
<br>
<input type="submit" name="Submit"value="Submit">
</div>
</form>
This code is works perfectly in my localhost. But when I publishe my project to IIS Server it is not working. It is returning -
Server Error: 404 File or Directory Not Found.
May be it conflicts with my physical path and requested path. How to resolve this problem?? :(
The action's url in the form tag may be wrong :
If the url for display and post the data is the same, you can remove action="/Home/Index"
If you want to specify the url, please use action="#Url.Action("Index")"
It will automatically resolve the Url.
My Code is working properly after using an tilde (~) sign before action.
For example:
action="~/Home/Index"
After using this sign my code works properly. It reduce the conflicts between virtual path and physical path.

how to post login array error within the originating page

Hi how do you post the login error message within the originating page where the user was attempting to login ?
Below I was able to stay on the current page if user login successfully but for login error it will obviously just go to the logonprocess page and display the error message.
Sorry that I remove a lot of validation below as the codes can really be very long.
Index.php
<?php
//set the session cookie parameter
ini_set("session.save_path", "sessionData");
session_start();
?>
<?php
if (!isset($_SESSION['uName'])) { ?>
<form method="post" action="logonProcess.php">
<div>Username <input type="text" name="userName" placeholder="Username"></div>
<div>Password <input type="password" name="pwd" placeholder="Password"></div>
<div><input type="submit" value="Logon"></div>
</form>
<?php } else { }?>
<?php
if (isset($_SESSION['uName'])) {
$username = $_SESSION['uName'];
echo "<p>Welcome $username</p>\n";
?>
Logout</br></br>
LogonProcess.php
$loginerror = array();
if (empty($username)) {
$loginerror[] = "You have not entered all of the required fields";
}
elseif (strlen($passWD) < 8) {
$loginerror[] = "You have not entered all of the required fields";
}
if (!empty($loginerror))
for ($a=0;$a<count($loginerror);$a++)
{
echo "$loginerror[$a] <br />\n";
}
else
if (mysqli_stmt_fetch($stmt))
{
if (password_verify($passWD, $passWDHash))
{
$_SESSION['uName'] = $username;
echo "<p>Login successful</p>";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
else
{
echo "<p>Please try to login again</p>";
}
why dont you put ur login error in $_SESSION["login_error"] and check in ur origin page if the session exits show the error then destroy the session after it.

qq-form does not upload file to S3 bucket and ignores {request: endpoint}, still returns 200

I am using FU-5.0.8 on Ubuntu14, apache2 php5. I successfully created page to drag n drop file, create signature and upload to my AWS S3 bucket.
I then integrated that code into an existing form, using the qq-form. The FU element and the form are generated correctly, I am able to enter data and the data is posted to my DB including the key file name generated by FU.
Issue 1: FU is not pointing to the bucket I have identified in my script. Instead of the correct bucket as before, it make my domain the target bucket name.
Issue 2: FU provides a progress bar and shows the upload is complete and returns 200. I don't know how this is possible, do FU check that the file actually exists upon completion?
Here are the standalone upload script and the script with the form. As you can see they have an identical endpoint. I have included the POST created from the qq-form where you can see the endpoint is incorrect.
FU in the JSON POST is setting the bucket to www.biggytv.com, which does not exist. It should got to btv_upload_org.s3.amazonaws.com
You assistance is appreciate.
FORM CODE
<form action="https://www.biggytv.com/btvChannels/FSsubmit.php" id="qq-form" class="span6">
<div id="fineuploader-s3" class="span6"></div>
<div class="form-group span2">
<label>Program Title</label>
<input type = "text" class="span4" name="program_title" maxlength="200" autofocus="" required>
</div>
<div class="form-group span6">
<label>Program Description</label>
<textarea name="description" maxlength="1000" class="span8" id="count_me" placeholder="Please do not include links in the Program Description. Add any links to content on other sites as part of your profile." required></textarea>
</div>
<div class="form-group span5">
<label>Video Language</label>
<select name="vid_language" class="span4" required>
<option value=""></option>
<?php $language->data_seek(0);
while($language_row = $language->fetch_assoc()){
$languageid = $language_row['short'];
$languagename = $language_row['name'];
echo "<option value=\"$languageid\">
$languagename
</option>";
}?>
</select>
</div>
<div class="form-group span5">
<label>Target Audience</label>
<select name="Audience_DART1" class="span4" required>
<option value=""></option>
<?php $audience->data_seek(0);
while($audience_row = $audience->fetch_assoc()){
$audienceid = $audience_row['tar_aud_code'];
$audiencename = $audience_row['tar_aud_name'];
echo "<option value=\"$audienceid\">
$audiencename
</option>";
}?>
</select>
</div>
<div class="form-group span5">
<label>Genre</label>
<select name="genre" class="span4" required>
<option value=""></option>
<?php $genre->data_seek(0);
while($genre_row = $genre->fetch_assoc()){
$genreid = $genre_row['genre_id'];
$genrename = $genre_row['genre_name'];
echo "<option value=\"$genreid\">
$genrename
</option>";
}?>
</select>
</div>
<div class="form-group span5">
<label>Rating</label>
<select name="Rating_DART" class="span4" required>
<option value=""></option>
<?php $rating->data_seek(0);
while($rating_row = $rating->fetch_assoc()){
$dartid = $rating_row['dart_rating'];
$dartname = $rating_row['dart_rating_name'];
echo "<option value=\"$dartid\">
$dartname
</option>";
}?>
</select>
</div>
<input type="hidden" name="content_owner_name" value=<?php echo $content_owner_name;?>>
<input type="hidden" name="channel_id" value="801102">
<div class="span6 offset2">
<input id="submitButton" type="submit" value="Submit" class="span4">
</div>
</form>
QQ-FORM
jQuery(document).ready(function ($) {
$('#fineuploader-s3').fineUploaderS3({
request: {
endpoint: "btv_upload_org.s3.amazonaws.com",
accessKey: "XXXXXXXX"
},
template: "qq-template",
signature: {
endpoint: "/finesig/"
},
forceMultipart: {
enabled: true
},
debug: true,
cors: {
expected:true,
},
resume: {
enabled: true
},
objectProperties: {
acl: "public-read"
},
validation: {
itemLimit: 1,
sizeLimit: 150000000,
acceptFiles: "video/mp4, video/quicktime, video/x-flv, video/x-ms-wmv",
allowedExtensions: ["mp4", "mov", "flv", "wmv"],
},
})
});
POST JSON
JSON
conditions
[Object { acl="public-read"}, Object { bucket="www.biggytv.com"}, Object { Content-Type="video/mp4"}, 12 more...]
0
Object { acl="public-read"}
1
Object { bucket="www.biggytv.com"}
2
Object { Content-Type="video/mp4"}
3
Object { success_action_status="200"}
4
Object { key="e001946c-a472-4412-9854-b44fede53e72.mp4"}
5
Object { x-amz-meta-program_title="Marcus%20Johns"}
6
Object { x-amz-meta-description="Marcus%20Johns"}
7
Object { x-amz-meta-vid_language="en"}
8
Object { x-amz-meta-audience_dart1="U"}
9
Object { x-amz-meta-genre="6"}
10
Object { x-amz-meta-rating_dart="G"}
11
Object { x-amz-meta-content_owner_name="MarcusJohns"}
12
Object { x-amz-meta-channel_id="801102"}
13
Object { x-amz-meta-qqfilename="7920637590280230638.mp4"}
14
["content-length-range", "0", "150000000"]
expiration
"2014-10-14T00:11:08.742Z
Uploader Log
[Fine Uploader 5.0.8] Sending simple upload request for 0
custom.....0.8.js (line 207)
[Fine Uploader 5.0.8] Submitting S3 signature request for 0
custom.....0.8.js (line 207)
[Fine Uploader 5.0.8] Sending POST request for 0
custom.....0.8.js (line 207)
POST https://www.biggytv.com/finesig/
200 OK
552ms
custom.....0.8.js (line 3810)
[Fine Uploader 5.0.8] Sending upload request for 0
custom.....0.8.js (line 207)
POST https://www.biggytv.com/btvChannels/FSsubmit.php
200 OK
938ms
custom.....0.8.js (line 9849)
[Fine Uploader 5.0.8] Received response status 200 with body: Array
(
[key] => 05a829e8-bea1-44f6-b35d-1f620f1043af.mp4
[AWSAccessKeyId] => XXXXXXXXX
[Content-Type] => video/mp4
[success_action_status] => 200
[acl] => public-read
[x-amz-meta-program_title] => Marcus%20John
[x-amz-meta-description] => Mar
[x-amz-meta-vid_language] => en
[x-amz-meta-audience_dart1] => U
[x-amz-meta-genre] => 6
[x-amz-meta-rating_dart] => G
[x-amz-meta-content_owner_name] => MarcusJohns
[x-amz-meta-channel_id] => 801102
[x-amz-meta-qqfilename] => 7920637590280230638.mp4
[policy] => eyJleHBpcmF0aW9uIjoiMjAxNC0xMC0xNFQwMDozNzoxNS44NjZaIiwiY29uZGl0aW9ucyI6W3siYWNsIjoicHVibGljLXJlYWQifSx7ImJ1Y2tldCI6Ind3dy5iaWdneXR2LmNvbSJ9LHsiQ29udGVudC1UeXBlIjoidmlkZW8vbXA0In0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDAifSx7ImtleSI6IjA1YTgyOWU4LWJlYTEtNDRmNi1iMzVkLTFmNjIwZjEwNDNhZi5tcDQifSx7IngtYW16LW1ldGEtcHJvZ3JhbV90aXRsZSI6Ik1hcmN1cyUyMEpvaG4ifSx7IngtYW16LW1ldGEtZGVzY3JpcHRpb24iOiJNYXIifSx7IngtYW16LW1ldGEtdmlkX2xhbmd1YWdlIjoiZW4ifSx7IngtYW16LW1ldGEtYXVkaWVuY2VfZGFydDEiOiJVIn0seyJ4LWFtei1tZXRhLWdlbnJlIjoiNiJ9LHsieC1hbXotbWV0YS1yYXRpbmdfZGFydCI6IkcifSx7IngtYW16LW1ldGEtY29udGVudF9vd25lcl9uYW1lIjoiTWFyY3VzSm9obnMifSx7IngtYW16LW1ldGEtY2hhbm5lbF9pZCI6IjgwMTEwMiJ9LHsieC1hbXotbWV0YS1xcWZpbGVuYW1lIjoiNzkyMDYzNzU5MDI4MDIzMDYzOC5tcDQifSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwiMCIsIjE1MDAwMDAwMCJdXX0=
[signature] => d48Ibli+V6/RmN3bUUZKVJ0woew=
)
custom.....0.8.js (line 207)
[Fine Uploader 5.0.8] Simple upload request succeeded for 0
Update
In the FU documentation you referred to "Integrating with existing html forms", the "simple example" 'action' is set to a script not a S3 bucket, that is why I am confused.
However, I have configured my script in the manner of your answer.
When I set the Action to the bucket, the uploadSuccess: {endpoint} POST does not include any of my form data, just key, uuid,name,bucket,etag.
If I set the Action as to https://www.biggytv.com/btvChannels/FSsubmit.php, the form data is sent in the POST and FU returns a 200 that the file was uploaded to www.biggytv.com, a bucket that does not exist.
So my issue is the uploadSuccess: {endpoint} is not including any of my form data in the POST.
Thank you.!
The action attribute in the form serves the same purpose as the request.endpoint option. You should leave the request.endpoint option off of your JavaScript configuration. The action attribute will define the S3 endpoint where your files will be uploaded. If you want the file to be sent to "btv_upload_org.s3.amazonaws.com", then that should be the value of the form's action attribute. Again, leave request.endpoint off your JavaScript config.
In your JavaScript config, you can (and must) define a signature.endpoint option. Fine Uploader will send a POST to this endpoint to sign each request before a request is sent to the S3 endpoint defined in the action attribute.
You may also define an uploadSuccess endpoint in your JavaScript config. Fine Uploader will POST to this location when the file is successfully in S3.
You can find all information regarding form support on the associated feature page.

Automatically grab file path

Everyone i am looking for a way to automatically upload a file but skip the browse and choose file process.
So i set the location of the file somehow via the form and the client just has to click submit and it will automatcially upload the file from the path i have set. skipping the browse for file process.
I would like to intergrate it into the following undesigns S3 Class
http://undesigned.org.za/2007/10/22/amazon-s3-php-class/documentation
<?php
S3::setAuth(awsAccessKey, awsSecretKey);
$bucket = "upload-bucket";
$path = "myfiles/"; // Can be empty ""
$lifetime = 3600; // Period for which the parameters are valid
$maxFileSize = (1024 * 1024 * 50); // 50 MB
$metaHeaders = array("uid" => 123);
$requestHeaders = array(
"Content-Type" => "application/octet-stream",
"Content-Disposition" => 'attachment; filename=${filename}'
);
$params = S3::getHttpUploadPostParams(
$bucket,
$path,
S3::ACL_PUBLIC_READ,
$lifetime,
$maxFileSize,
201, // Or a URL to redirect to on success
$metaHeaders,
$requestHeaders,
false // False since we're not using flash
);
$uploadURL = "https://{$bucket}.s3.amazonaws.com/";
?><!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>
<title>S3 Form Upload</title>
</head>
<body>
<form method="post" action="<?php echo $uploadURL; ?>" enctype="multipart/form-data">
<?php
foreach ($params as $p => $v)
echo " <input type=\"hidden\" name=\"{$p}\" value=\"{$v}\" />\n";
?>
<input type="file" name="file" /> <input type="submit" value="Upload" />
</form>
</body>
</html>
at what point does it grab the file path ?
is it grabbing it out of the name here
can i do something with $_FILES ???
Can someone please give me a point on where to start i would really appriciate this.
thanks
You'll have to specify the tools of the trade. A common html form has no such functionality.
You can try value="c:\somefile.ext" but many browsers will not accept this.