Input mp3 file returns 0 - php

When I try to input an mp3 file the $_FILES returns null.
Controller:
$audio = $_FILES['muziek']['tmp_name'];
if ($audio != ''){
$audioContent = file_get_contents($audio);
$this->load->model('muziek_model');
$this->muziek_model->insertMuziek($audioContent);
}
var_dump($audio);
var_dump($audioContent);
View:
<?php echo form_open_multipart('Muziek/uploadMuziek');?>
<table>
<tr>
<td><?php echo form_label('MP3 Bestand:', 'muziek'); ?></td>
<td><input type="file" name="muziek" id="muziek" accept=".mp3" style="margin-left: 10px; padding-bottom: 35px; color: black" class="btn btn-login form-control login-formcontrol bg-white"/></td>
</tr>
<tr>
<td></td>
<td>
<?php echo form_submit('knop', 'Uploaden', 'class = "btn btn-login login-formcontrol"'); ?>
</td>
</tr>
</table>
<?php echo form_close();?>
When I select an mp3 file audio should not be null

File uploads can fail for a variety of reasons. https://www.php.net/manual/en/features.file-upload.errors.php
Your's is failing because it is too big:
Value: 1; The uploaded file exceeds the upload_max_filesize directive
in php.ini.
If you have access to php.ini you can change this variable to make it accept larger files.
Even if you do this with success, I would suggest checking for upload errors if(!isset($_FILES['muziek']['tmp_name']) || $_FILES['muziek']['error'] !== 0) { echo 'error'; } before trying to perform actions on a file that may or may not exist.
I personally use: https://github.com/verot/class.upload.php
but Codeigniter has an in-built upload library.

Related

database doesn't show using GET method

I need help.i have this database
student_code: 1234
student_id: angel
namaFoto: angel.jpg
using GET method to call specific data from database, i use this code below, but the data doesn't show up. what did i do wrong?
<?php
include_once "library/inc.sesadmin.php";
$row = 25;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 1;
if($usertype != 'Admission'||$usertype != 'Administrator'){
if($_GET) {
$Kode = $_GET['Kode'];
$myQry=$db->prepare("SELECT * FROM student WHERE student_code='$Kode'");
$myQry->execute();
$myQryCount = $myQry->rowCount();
while ($myData = $myQry->fetch()) {
}
}
?>
<table >
<tr>
<td ><img src="foto/<?php echo $namaFoto; ?>"></td>
<td ><b>Code</b></td>
<td ><b>:</b></td>
<td ><?php echo $myData['student_code']; ?></td>
</tr>
<tr>
<td><b>Student ID </b></td>
<td><b>:</b></td>
<td> <?php echo $myData['student_id']; ?> </td>
</tr>
</table>
<?php } else { ?>
<br /> <br /> <br /> <br /> <br /> <br />
<p align="center">You are not authorized to access this area</p>
<?php } ?>
Are you including ?Kode=1234 on the URL you are using to access the page? Also the image isn't using the same $myData collection to retrieve the image value. That may not be a root-cause issue, but does look to be a big.

Save screenshot using html2canvas to web folder

I have a website, where user can take screenshot of that website and that screenshot should save automaticly to folder "posters" inside my "www" folder.
But when I try to make an screenshot, it is saved directly to "www" folder and not to the "posters" folder. I tried to change atributes of the "posters" folder to 777 but It did not helped. And also, that "posters" folder gives this error: Forbidden You don't have permission to access /posters/ on this server. when I try to visit it via browser. I dont know what is wrong.
Here is my save.php code:
<?php
//Get the base-64 string from data
$filteredData = substr($_POST['img_val'], strpos($_POST['img_val'], ",") + 1);
//Decode the string
$unencodedData = base64_decode($filteredData);
//Save the image
file_put_contents('img_' . date("U") . '.png', $unencodedData);
move_uploaded_file('img.png', './posters/$newname');
?>
<h2>Save the image and show to user</h2>
<table>
<tr>
<td>
<a href="img.png" target="blank">
Click Here to See The Image Saved to Server</a>
</td>
<td align="right">
<a href="index.php">
Click Here to Go Back</a>
</td>
</tr>
<tr>
<td colspan="2">
<br />
<br />
<span>
Here is Client-sided image:
</span>
<br />
<?php
//Show the image
echo '<img src="' . $_POST['img_val'] . '" />';
?>
</td>
</tr>
</table>
<style type="text/css">
body, a, span {
font-family: Tahoma; font-size: 10pt; font-weight: bold;
}
</style>
Is it possible to make something like this? file_put_contents(.PathToFolder/'img_' . date("U") . '.png', $unencodedData);

What am I missing or doing wrong, trying to get image out of database using BLOB

I am trying to get images out of the database using Blob, I know its not secure but it is for demo purposes. Below is the code I have at the moment.
<?php
error_reporting(0);
require './db/connect.php';
include './includes/header.php';
?>
<?php
if($result = $connection->query("SELECT * FROM Production")){
if($count = $result->num_rows){
while($row = $result->fetch_object()){
?>
<table class="productioninfo" style="width: auto; height: auto; border: 5px black solid;">
<tr>
<th>Image:</th>
<td><img src="/phpmyadmin/production/<?php echo $row->ProductionId;?>.jpeg" </td>
<th>Production Name:</th>
<td><?php echo $row->ProductionName; ?></td>
<th>Production Type:</th>
<td><?php echo $row->ProductionType; ?></td></br>
</tr>
<?php
}
$result->free();
}
}
echo $result;
include './includes/footer.php';
Also I want to know how to do it the other way, by having the file path in the database and then displaying it on the web page.
Many Thanks for your help!
An arror in this line:
<td><img src="/phpmyadmin/production/<?php echo $row->ProductionId;?>.jpeg"</td>.
Try to close correctly the img tag :
<td><img src="/phpmyadmin/production/<?php echo $row->ProductionId;?>.jpeg" /></td>
Then be sure that the image was correctly encoded and decoded respectively when storing and retrieving.
While saving an image to database, You have to encode it and then save to db. & while showing it in HTML you have to decode it.
eccoding :
$img_encoded = base64_encode('your image');
decode and show in HTML
<img src="data:image/jpg;base64,'.$img_encoded.'"/>

Retrieving images from the path data saved at SQL database

Part of my code to retrieve the stores images and the content from the SQL database (only the path is saved at the database) is as follows. I get the content displayed except the images.
My database record says the path as; C:/xampp/htdocs/bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG
The image source I entered does not seems to be helping me. How do I adjust my approach to make sure the pictures are extracted from the database?
code as follows;
<?php
$j=0;
while ($rows = mysql_fetch_assoc($query))
{
?>
<tr style="height:100px; font-family: Georgia, 'Times New Roman', Times, serif;">
<td style=" width:100px;">
<img src='<?php $rows['pictures'];?>'><br><br>
</td>
<td style="text-align:justify;"><?php echo $rows['description'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['brand'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['model'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['unitprice'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['availability'];?> units available<br><br></td>
<td><input type='submit' id='buynow[]' class='buynow' name='but' value='Buy'><br><br></td>
</tr>
<?php
$j++;
}
echo "</table>";
}?>
You have to insert only relative path excluding your document root. That is if your document root is set till htdocs folder only (which is default in apache for localhost) then you have to insert image path from this document root in your case
/bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG
And yes you need to echo that variable too.
Try html link first
<img src='bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG' />
Ok
Try this fixed:<img src='<?php echo substr_replace($rows['pictures'], '',0, 16);?>'/>

how to invoke JS/ajax with no submit button on the page?

i have a website page that contains only data of which one field gives the number of messages in your inbox, and i need to refresh this as new messages can some in at any time, so the user, while on this page can see there are new messages. how can i call my JS/ajax to do the refresh please?
i tried header("Refresh:10"); but client was not happy as it refreshes the whole page, he only wants the no of messages to refresh as they come in...can someone help please? thanks
my code for this page:
<?php use_stylesheets_for_form($search_form) ?>
<?php use_javascripts_for_form($search_form) ?>
<div id='div_longgray_gradient2'>
<div id='div_float_img'>
<br/>
<table width='96%' border='0'>
<tr>
<td colspan='2' align='right'>
<form action="<?php echo url_for('profiles/search' ) ?>" method="post" >
<table>
<tr>
<td>
<span class='spn_med_lightblue_rbc'>Profile Search
</span>
<?php echo $search_form['uc_other']->render(array('default')); ?> </td>
<td><input class='submit_img' type="image" src="/images/rainbow/gobuttonbluesmall.png" value="Submit" alt="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td rowspan='2' width='40px' align='left'>
<img src='/images/rainbow/arrow.png'>
</td>
<td align='left'>
<span class='spn_big_black_rbc'>WELCOME <?php echo $usr_profile->getName() ?></span>
</td>
<td align='left'>
<?php
if (0)
{
// $filename = $usr_profile->getMsisdn();
$filename = $usr_profile->getProfilePicPath();
if ($filename && file_exists($filename))
{
$source = imagecreatefromjpeg($filename);
}
else
{
$filename = $usr_profile->getDefaultProfilePicPath();
$source = imagecreatefromjpeg($filename);
echo "<span class='spn_big_black_rbc'>You have not uploaded an image yet</span>";
}
}
if($usr_profile->existsProfilePic()==FALSE)
{
echo "<span class='spn_big_black_rbc'>You have not uploaded an image yet</span>";
echo "</br>";
}
if($usr_profile->checkForMissingInfo()== 1)
{
echo "<span class='spn_big_black_rbc'>You have some missing info</span>";
echo " ";
echo link_to('Edit','profile/edit','class=link_medium');
}
?>
</td>
</tr>
<tr>
<td align='left'>
<span class='spn_med_lightblue_rbc'>TO RAINBOW</span>
<span class='spn_med_black_rbc'>CODE</span>
<span class='spn_med_lightblue_rbc'>...SHINE ON</span>
</td>
<td>
</td>
</tr>
</table>
<br/>
<table class='table_border_light' width='820px'>
<tr>
<td class='td_header_blue' colspan='3' align='left'>
<span class='spn_big_black_rbc'>
MY FEEDS
</span>
</td>
<td class='td_header_blue' colspan='3' align='left'>
<span class='spn_big_black_rbc'>
RAINBOWCODE NEWS
</span>
</td>
</tr>
<tr>
<td valign='top' colspan='3' width='50%' align='left'>
<span class='spn_med_black_rbc'>You have <?php echo $new_mail_cnt ?> new </span>
<?php echo link_to('Messages','messagebox/list','class=link_medium_blue'); ?>
</br>
<span class='spn_med_black_rbc'>You have
<?php
echo sizeof($block_records);
?> blocked users </span>
</td>
<td valign='top'colspan='3' width='50%' align='left'>
<ul>
<li>
<a href="http://spreadsheets.google.com/a/miranetworks.net/spreadsheet/viewform?formkey=dEVlYTdJTzZiU0JPTnZqYWlZQTJRZ0E6MQ" class='link_medium_blue'> Rate us! Complete the online questionnaire</a></b>
</li>
<?php
foreach($news as $news_item)
{
echo "<li>".$news_item->getNews(). "</li>";
$newsId = $news_item->getId();
if ($newsId == 1)
{
//some echos here to display text
}
}
?>
</ul>
</td>
</tr>
<tr>
<td colspan='3' align='left'>
<span class='spn_big_black_rbc'>
MOOD BAROMETER
<?php echo link_to('how does it work?','util/barometer','class=link_medium_blue'); ?>
</span>
<?php
include_component('profile','moodmetershow');
?>
</td>
<td colspan='3' align='left'>
<?php
include_component('profile','moodmeter');
?>
</td>
</tr>
<tr>
<td colspan='3' align='left'>
</td>
</tr>
</table>
</div>
</div>
i added this for $new_mail_cnt:
echo $new_mail_cnt = '<script type="text/javascript">getMessages();</script>';
then i have:
<script language="JavaScript" type="text/javascript">
var receiveReq = getXmlHttpRequestObject();
var mTimer;
function getXmlHttpRequestObject()
{
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
document.getElementById('p_status').innerHTML =
'Status: Cound not create XmlHttpRequest Object.' +
'Consider upgrading your browser.';
}
}
function getMessages()
{
receiveReq = getXmlHttpRequestObject();
if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
{
receiveReq.open("POST", 'getMessage.php', true);
receiveReq.onreadystatechange = handleReceiveMessage();
receiveReq.send(null);
document.getElementById('new_messages').innerHTML = receiveReq.responseXML; //not sure here
}
mTimer = setTimeout('getMessage();',2000);
}
function handleReceiveMessage()
{
if (receiveReq.readyState == 4)
{
var chat_div = document.getElementById('div_chat');
var xmldoc = receiveReq.responseXML;
var message_nodes = xmldoc.getElementsByTagName("message");
}
}
</script>
AJAX is a technology which allows you to launch web requests to a server after the page is loaded. When using an AJAX request, the page does not have to reload (indeed, the user won't even notice a request is taking place).
You should launch an AJAX request to your server, which will check for any new messages.
To continuously check for new messages, you could create a timer using either the window.setTimeout, or the window.setInterval methods, to launch an AJAX request at designated periods.
Whilst I am not a big fan of promoting using libraries when a question does not mention any use of them, you may find that using one (such as jQuery), will greatly simplify the process of managing AJAX requests, as it comes with a complete module which does the hard work for you.
Regardless of whether you choose to use a library to perform your AJAX request or not, the workflow for the solution will be as follows:
On a timer (every 10 seconds say, launch an AJAX request) to a webpage on your server (e.g checkfornewmessages.php).
On your server, check for any new messages, and include what you want to display to the user in the output (e.g. the number of new messages, the title of the messages, whatever).
In your callback for your AJAX request, set the response of the AJAX call (which will contain the output you created in your PHP code), to the contents of one of the DOM elements on your page (e.g. <span class='spn_med_black_rbc'>You have <?php echo $new_mail_cnt ?> new </span>).
Try timer in javascript http://www.w3schools.com/js/js_timing.asp
I am assuming in your use_javascripts_for_form($search_form) you have a jQuery reference somewhere if not you can download it and include it in the headers
======NOTE UNTESTED======
Change the following line
<span class='spn_med_black_rbc'>You have <?php echo $new_mail_cnt ?> new </span>
to
<span class='spn_med_black_rbc'>You have <div id='newMessageDiv'><?php echo $new_mail_cnt ?></div> new </span>
Add something like the following into the HEAD tag
$(document).ready(function() {
$("#newMessageDiv").load
("newMessageCheck.php");
var refreshId = setInterval(function() {
$("#newMessageDiv").load('newMessageCheck.php?randval='+ Math.random());
}, 10000);
$.ajaxSetup({ cache: false });
});
This will attempt to refresh the div every 10 seconds with the contents of newMessageCheck.php, this file should just output a single value of just the amount of current new messages.
you put:
setTimeout(samefunction,milliseconds)
in the function that you want to auto-recharge and call the same
this create a infinite loop waiting x milliseconds

Categories