I've searched around this site for an answer but couldn't find any help in my problem.
I have a script with a form and I'd like to get the contents of the input written into a txt file (line by line in mytext.txt file for example) when the submit button is pressed - or maybe simpler only the result.
Result / content of "echo $result['text'];" should be saved to text file (mytext.txt)
I tried to add something like that after each "echo" but it doesn't work. here is the sample code.
$f = fopen("mytext.txt", "w");
fwrite($f, $result);
fclose($f);
or
$f = fopen("mytext.txt", "w");
fwrite($f, $username);
fclose($f);
or
$txt = "$result";
$myfile = file_put_contents('mytext.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
but still no luck.
How can I do that and where to add it? With PHP or maybe with JavaScript? Help please.
edit:
PART of the script (I'm sorry I forgot about it)
<?php
if(count($check_ex) == 2){
$ex_name = $check_ex[0]."_".$check_ex[1];
}else{
$ex_name = $check_ex[0];
}
$additional_button = "<a href='javascript:void(0)' onclick='submitform_$dom_$ex_name()' ><button id='buy' class='btn btn-success btn-xs pull-right order-btn'>".__($additional_button_name, 'kate')."</button></a>";
}elseif($integration == 'woocommerce'){
if($show_price){
$show_price = '- '.kate_display_price($username).__('/year','kate');
}
$additional_button = "<a href='?&add-to-cart=$additional_button_link&username=$username' id='buy' class='btn btn-success btn-xs pull-right order-btn' $buy_new_tab >".__($additional_button_name,'kate')." $show_price</a>";
}elseif($integration == 'custom'){
if(!$additional_button_name == '' AND !$additional_button_link == ''){
$additional_button_links = str_replace( '{username}', $username, $additional_button_link );
$additional_button = "<a id='buy' class='btn btn-success btn-xs pull-right order-btn' href='$additional_button_links' $buy_new_tab >".__($additional_button_name,'kate')."</a>";
}else{
$additional_button = '';
}
}else{
$additional_button = '';
}
$custom_not_found_result_text = str_replace( '{username}', $username, $custom_not_found_result_texts );
$whmcs = "<script type='text/javascript'>
function submitform_$dom_$ex_name()
{
document.whmcs_$dom_$ex_name.submit();
}
</script>
<form method='post' name='whmcs_$dom_$ex_name' id='whmcs' action='$additional_button_link/cart.php?a=add&username=register' $buy_new_tab>
<input type='hidden' name='usernames[]' value='$username' >
<input type='hidden' name='usernamesregperiod[$username]' value='1'>
</form>";
if ($available->status == 1) {
$result = array('status'=>1,
'username'=>$username,
'text'=> '<div class="callout callout-success alert-success clearfix available">
<div class="col-xs-10" style="padding-left:1px;text-align:left;">
<i class="glyphicon glyphicon-ok" style="margin-right:1px;"></i> '.__($custom_found_result_text,'kate').' </div>
<div class="col-xs-2" style="padding-right:1px">'.__($additional_button,'kate').' '.$whmcs.'</div>
</div>
');
echo $result['text'];
} elseif($available->status == 0) {
$result = array('status'=>0,
'username'=>$username,
'text'=> '<div class="callout callout-danger alert-danger clearfix not-available">
<div class="col-xs-10" style="padding-left:1px;text-align:left;">
<i class="glyphicon glyphicon-remove" style="margin-right:1px;"></i> '.__($custom_not_found_result_text, 'kate').'
</div>
<div class="col-xs-2" style="padding-right:1px">'.$www_link.'</div>
</div>
');
echo $result['text'];
}elseif ($available->status == 2) {
$result = array('status'=>2,
'username'=> $username,
'text'=> '<div class="callout callout-warning alert-warning clearfix notfound">
<div class="col-xs-10" style="padding-left:1px;text-align:left;">
<i class="glyphicon glyphicon-exclamation-sign" style="margin-right:1px;"></i> '.__('not found','kate').'
</div>
</div>
');
echo $result['text'];
}
}
}
else
{
echo 'Please enter the username';
}
}
If you are having errors when trying to get this code to run, check that you have granted your PHP file access to write information to the hard drive.
The code is correct, it may be that the directory does not have permission to create files.
You must check if the directory you're trying to save your txt file is writable.
Example:
$contents = 'Here goes your content';
$dirName = __DIR__; //in case you're saving in another directory, you may use 'files/directory/' instead of __DIR__
$fileName = $dirName.'/mytext.txt';
if (!is_writable($dirName)) {
throw new \Exception("This folder is not writable: '$dirName'");
}
//Checks if the content was added
if (!file_put_contents($fileName, $contents)) {
throw new \Exception("Could not write to file: $fileName");
}
Related
I would like a help with jQuery File Upload, I'm sorry if my English is not correctI would like to show the images by passing an ID parameter through the url or some hidden field because I have a gallery and each gallery has its images.
<div class="container-fluid">
<!-- The file upload form used as target for the file upload widget -->
<!-- estava assim action="//jquery-file-upload.appspot.com/"-->
<form id="fileupload" action="server/php/UploadHandler" method="POST" enctype="multipart/form-data">
<!-- Redirect browsers with JavaScript disabled to the origin page -->
<noscript>
<input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/">
</noscript>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="col-lg-7">
<!-- The fileinput-button span is used to style the file input field as button -->
<!--the hidden input is used to get id by GET in the parameter to urledit= -->
<input type="hidden" name="urledit" value="<?php echo $urledit; ?>">
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Add fotos...</span>
<input type="file" name="files[]" multiple>
</span>
<button type="submit" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Iniciar upload</span>
</button>
<button type="reset" class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancelar upload</span>
</button>
<button type="button" class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Apagar</span>
</button>
<input type="checkbox" class="toggle">
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="col-lg-5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
</form>
</div>
Database class:
<?php
include_once 'config.php';
class conn extends config
{
var $pdo;
function __construct()
{
$this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->user, $this->pass);
}
function getImages($urledit)
{
//$urledit = '9';
$stm = $this->pdo->prepare("SELECT gallery_img FROM site_gallery WHERE gallery_galeria_id = '$urledit'");
$run = $stm->execute();
$array = array();
while ($rs = $stm->fetch(PDO::FETCH_ASSOC)) {
array_push($array,$rs['gallery_img']);
}
return $array;
}
function deleteImages($foto)
{
$stm = $this->pdo->prepare("DELETE FROM site_gallery WHERE gallery_img = :foto");
$stm->bindValue(":foto",$foto);
$run = $stm->execute();
}
function insertImages($id,$foto,$data)
{
try{
$stm = $this->pdo->prepare("INSERT INTO site_gallery (gallery_galeria_id, gallery_img, gallery_data) VALUES (:id,:foto,:data)");
$stm->bindValue("id",$id);
$stm->bindValue("foto",$foto);
$stm->bindValue("data",$data);
$run = $stm->execute();
//echo $stm->rowCount();
}catch(PDOException $e){
echo 'Error: '. $e->getMessage();
}
}
}
?>
UploadHandler.php
to insert into the database works
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = new \stdClass();
$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
$index, $content_range);
$file->size = $this->fix_integer_overflow((int)$size);
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
mkdir($upload_dir, $this->options['mkdir_mode'], true);
}
$file_path = $this->get_upload_path($file->name);
$append_file = $content_range && is_file($file_path) &&
$file->size > $this->get_file_size($file_path);
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
//insere no banco
$data = date('Y-m-d H:i:s');
$urledit = $this->get_url_edit('urledit');
$conn = new conn();
$conn->insertImages($urledit,$file->name,$data);
$conn->getImages($urledit);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
but this select does not work:
protected function get_file_objects($iteration_method = 'get_file_object') {
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
return array();
}
$urledit = $this->get_url_edit('urledit');
//$urledit = '9';
$conn = new conn();
$Images = $conn->getImages($urledit);
return array_values(array_filter(array_map(
array($this, $iteration_method),
//scandir($upload_dir)
$Images
)));
}
because it has no value for $Images = $conn->getImages($urledit);
can anybody help me?
Alguém poderia me ajudar? pode ser em português também.
I'm working on a Content Management System using PHP for controlling over my Telegram Bot. Basically what I have done till now is that I can read the messages that people has sent to my Telegram Bot and answer to them.
In order to do that, I coded this:
<?php
$botToken = '423495534:asdsadsadasdsadsa';
$website = 'https://api.telegram.org/bot'.$botToken;
$update = file_get_contents($website."/getUpdates");
$updateArray = json_decode($update, TRUE);
$info = file_get_contents($website."/getme");
$infoArray = json_decode($info, TRUE);
$num = count($updateArray["result"]);
$sender_ids = array();
$sender_infos = array();
for($i=0;$i<$num;$i++){
$sender_id = $updateArray["result"][$i]["message"]["from"]["id"];
$sender_isbot = $updateArray["result"][$i]["message"]["from"]["is_bot"];
$sender_fname = $updateArray["result"][$i]["message"]["from"]["first_name"];
$sender_lname = $updateArray["result"][$i]["message"]["from"]["last_name"];
$sender_uname = $updateArray["result"][$i]["message"]["from"]["username"];
$sender_type = $updateArray["result"][$i]["message"]["chat"]["type"];
$sender_msg = $updateArray["result"][$i]["message"]["text"];
$sender_date = $updateArray["result"][$i]["message"]["date"];
if(false === $key = array_search($sender_id, $sender_ids)){
$sender_ids[] = $sender_id;
$sender_infos[] = [
'sender_id' => $sender_id,
'sender_isbot' => $sender_isbot,
'sender_fname' => $sender_fname,
'sender_lname' => $sender_lname,
'sender_uname' => $sender_uname,
'sender_type' => $sender_type,
'sender_msg' => [$sender_msg],
'sender_date' => [$sender_date]
];
}else{
$sender_infos[$key]['sender_msg'][] = $sender_msg;
$sender_infos[$key]['sender_date'][] = $sender_date;
}
}
$num2 = count($sender_ids);
for($j=0;$j<$num2;$j++){
$id = $sender_infos[$j]["sender_id"];
$first_name = $sender_infos[$j]["sender_fname"];
$last_name = $sender_infos[$j]["sender_lname"];
$username = $sender_infos[$j]["sender_uname"];
$messages = $sender_infos[$j]["sender_msg"];
$acc_type = $sender_infos[$j]["sender_type"];
$isbot = $sender_infos[$j]["sender_isbot"];
$num1 = count($messages);
echo '
<div class="col-md-3">
<div class="box box-danger direct-chat direct-chat-danger">
<div class="box-header with-border">
<h3 class="box-title">'.$first_name.'</h3>
<sup>'.$acc_type.' - '.$isbot.'</sup>
<div class="box-tools pull-right">
<span data-toggle="tooltip" title="'.$num1.' New Messages" class="badge bg-red">'.$num1.'</span>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-toggle="tooltip" title="Contacts" data-widget="chat-pane-toggle">
<i class="fa fa-comments"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div class="box-body">
<div class="direct-chat-messages">
<div class="direct-chat-msg">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-left">';
echo '<strong>'.$first_name.'</strong>';
echo '
</span>
</div>';
for($i=0;$i<$num1;$i++){
echo '<div class="direct-chat-text">';
$text = $sender_infos[$j]["sender_msg"][$i];
if($text[0] === '/') {
echo ''.$text.'';
}else{
echo $text;
}
echo '<span class="direct-chat-timestamp pull-right">';
// echo date('l', $sender_infos[$j]["sender_date"][$i]);
echo '</span>';
echo '</div>';
}
echo '
</div>
<div class="direct-chat-msg right">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-right">'.$bot_fname.'</span>
</div>
<img class="direct-chat-img" src="
';
if ($dataSet->GetAvatar() != NULL){
echo $dataSet->GetAvatar();
}else{
echo "img/noprofilepic.jpg";
}
echo '
" alt="Message User Image">
';
$num3 = count($request_params["text"]);
foreach($_SESSION['messages'] as $reply){
echo '<div class="direct-chat-text">';
echo $reply;
echo '</div>';
}
echo '
</div>
</div>
<div class="direct-chat-contacts">
<ul class="contacts-list">
<li>
<a href="#">
<div class="contacts-list-info">
<span class="contacts-list-name">
';
echo $first_name = $sender_infos[$j]["sender_fname"];
echo ' </br> ';
echo $last_name = $sender_infos[$j]["sender_lname"];
echo ' </br> ';
echo ' <a target="_blank" href="http://www.t.me/'.$username.'">'.$username.'</a>';
echo ' </br> ';
echo ' <small class="contacts-list-date pull-right">'.$id.'</small>
</span>
<span class="contacts-list-msg">QUOTE</span>
</div>
</a>
</li>
</ul>
</div>
</div>';
if (isset($_POST['send'])){
$pm = $_POST['message'];
array_push($_SESSION['messages'], $pm);
$request_params = [
'chat_id' => $id,
'text' => $pm
];
echo "<META HTTP-EQUIV='Refresh' Content='0; URL=telegrambots.php?user_name=".$user_name."'>";
$request_url = 'https://api.telegram.org/bot' . $botToken . '/sendMessage?' . http_build_query($request_params);
$response = file_get_contents($request_url);
}
echo '
<div class="box-footer">
<form action="" method="post">
<div class="input-group">
<input type="text" name="message" placeholder="Write your direct message" class="form-control">
<span class="input-group-btn">
<input name="send" type="submit" class="btn btn-danger btn-flat"/>
</span>
</div>
</form>
</div>
</div>
</div>
';
}
?>
Basically what it does is that it grabs the latest updates of my Bot and count the number of results and save it in $num. Then with a for loop I tried to divide every information about the user who has sent message. After that I store all the required information of sender in a separated array called $sender_infos. And the next for loop shows a basic Chat Box depending on the number of users.
This whole thing makes this:
So it works fine and perfect but the problem is that, whenever I try answering to one conversation, it sends the message to all the available users. This issue comes from the for loop which divides every users by the Chat Box.
However what I want to do is to send a SINGLE DIRECT MESSAGE to a CUSTOM user and NOT ALL OF THEM.
I hope I have explained my problem well, so you could understand. If not, please comment me for more information and additional updates.
NOTE: I don't want a quick answer to this question. Because I'm facing this for several days and I don't know how to solve it. Please make sure you understand what I'm asking for and then add your suggest.
Thanks in advance...
I'm passing a folder name and path via a $_GET. All is fine until I pass a folder name containing and (&) ampersand then the folder name is cut short. i.e folder name test & replace is shorted to 'test '.
Have tried str_repalce, htmlentites, htmlspecialchars
$dir_path = $_GET['path'].$_GET['folder'];
The whole code:
<div class="panel-body" style="font-size:14px">
<?php
if(isset($_GET['path'])){
$dir_path = $_GET['path'].$_GET['folder']."/";
echo "full path = ".$dir_path."<br>folder = ".$Folder;
}else{
$dir_path = PUBLICPATH."/Folderholder/".$branch."/"; // branch url to that branchs folders and in $_GET['folder'];
}
//$dir = opendir($dir_path);
$mappath = str_replace(PUBLICPATH."/Folderholder/","",$dir_path);
echo "<p><i class='fa fa-sitemap'> <b>".$mappath."</b></i></p>\n"; ?>
<div class="row">
<div class="col-md-6">
<?php
echo "<button onclick='goBack()' class='btn btn-primary btn-sm'>Return</button><P>\n";
?>
</div>
<div class="col-md-6">
<?php
if(parent::$UM->get('Level') !== 'User' and $branch !== 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}elseif(parent::$UM->get('Level') == 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}
?>
</div>
</div>
<div class="row"><div class="col-md-12"> </div></div>
<table width="70%">
<?php
$files = scandir($dir_path);htmls
foreach ($files as $file)
{
if($file != "." && $file != "..")
{
echo "<tr>\n";
if(is_dir($dir_path.$file)){
echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".$file."'>$file</a></td>\n";
echo "<td> </td>\n";
}else{
echo "<td><i class='fa fa-download'></i> ".$file."</td>\n<td><a href='http://downloadfolder/download1.php?file=".$dir_path.$file."' target='_Blank'>Download</a></td>\n";
}//change path as required
echo "</tr>\n";
}
}
?>
</table>
</section>
</div>
The & character is used to separate key=value pairs in the query string.
When you generate the query string you should express it as an escape sequence: %26.
How you do that depends on how you are generating the query string in the first place.
You've tagged this php, but the PHP code you have shared is reading the data. You haven't shown us the code for generating it, but assuming that is still PHP:
To generate it in PHP you would normally use http_build_query:
$query = http_build_query(Array( path => "example&example", folder => "example&example" ));
urlencode should do the trick. It is specifically used for passing parameters to a URL to use as variables, as you are doing in your GETs.
Though previous answers in this thread are not incorrect, please also consider using rawurlencode as it will generate a more standards compliant (RFC 3986) URI. urlencode triggers the legacy encoding where spaces are replaced by plus-signs. (Anyone remember that?)
To stop the cut off of the folder name.
Two coding changes $dir_path = $_GET['path'].$_GET['folder']."/"; changed to
$dir_path = $_GET['path'].rawurldecode($_GET['folder'])."/";
and echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".$file."'>$file</a></td>\n";
changed to
echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".rawurlencode($file)."'>$file</a></td>\n";
<div class="panel-body" style="font-size:14px">
<?php
if(isset($_GET['path'])){
$dir_path = $_GET['path'].$_GET['folder']."/";
}else{
$dir_path = PUBLICPATH."/Folderholder/".$branch."/"; // branch url to that branchs folders and in $_GET['folder'];
}
//$dir = opendir($dir_path);
$mappath = str_replace(PUBLICPATH."/Folderholder/","",$dir_path);
echo "<p><i class='fa fa-sitemap'> <b>".$mappath."</b></i></p>\n"; ?>
<div class="row">
<div class="col-md-6">
<?php
echo "<button onclick='goBack()' class='btn btn-primary btn-sm'>Return</button><P>\n";
?>
</div>
<div class="col-md-6">
<?php
if(parent::$UM->get('Level') !== 'User' and $branch !== 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}elseif(parent::$UM->get('Level') == 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}
?>
</div>
</div>
<div class="row"><div class="col-md-12"> </div></div>
<table width="70%">
<?php
$files = scandir($dir_path);htmls
foreach ($files as $file)
{
if($file != "." && $file != "..")
{
echo "<tr>\n";
if(is_dir($dir_path.$file)){
echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".$file."'>$file</a></td>\n";
echo "<td> </td>\n";
}else{
echo "<td><i class='fa fa-download'></i> ".$file."</td>\n<td><a href='http://downloadfolder/download1.php?file=".$dir_path.$file."' target='_Blank'>Download</a></td>\n";
}//change path as required
echo "</tr>\n";
}
}
?>
</table>
</section>
</div>
Use urlencode to encode the url like:
$encodedURL = urlencode ('Your url');
Explanation: urlencode will encode the special characters to their entity values and than use it.
So, I am making a slideshow inside a modal. The idea is when user clicks "Slideshow", a modal will popup showing a slideshow of images. However when I click next button to view the next image, the modal suddenly closes. I tried putting the code to disable any external or button clicks but it still closes.
here is the code:
<button type="button" id="slide" class="btn btn-primary" data-toggle="modal" data-target="#mySlider">Persembahan Slaid</button><br><br><br>
<div class="modal fade" id="mySlider" tabindex="-1" role="dialog" aria-labelledby="mySliderLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Tutup</span></button>
<h4 class="modal-title" id="mySliderLabel"><?php echo $title?></h4>
</div>
<div class="modal-body">
<form ACTION="" method = "POST" enctype="multipart/form-data">
<div class="form-group">
<div class="w3-content w3-display-container">
<?php
$sql = "SELECT * FROM storytelling WHERE title = '$title' ORDER BY id";
$result = mysqli_query($db, $sql);
while($row = $result -> fetch_array())
{
?>
<div class="w3-display-container mySlides">
<?php echo "<img src = 'images/".$row['image']."' style='width:100%'>"; ?>
<div class="w3-display-bottomright w3-large w3-container w3-padding-16 w3-black">
<?php echo $row['text']?>
</div>
</div>
<?php
}
?>
<button class="w3-button w3-display-left w3-black" onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-display-right w3-black" onclick="plusDivs(1)">❯</button>
<script>
$(document).ready(function() {
$(window).keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
return false;
}
});
});
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Tutup</button>
<?php if(isset($_POST['save']))
{
//target folder to keep the media
$target = "images/".basename($_FILES['image']['name']);
//get all submitted data from form
$image = $_FILES['image']['name'];
$text = $_POST['text'];
if(!empty($_FILES['image']['name']))
{
$sql = "INSERT INTO storytelling(title, image, text ) VALUES ('$title', '$image', '$text')";
$result=mysqli_query($db, $sql);
if($result){
$message = "Cerita akan ditambah selepas diluluskan admin";
echo "<script type='text/javascript'>alert('$message');</script>";
header("Refresh:0");
} else {
$message = "Cerita gagal ditambah";
echo "<script type='text/javascript'>alert('$message');</script>";
}
move_uploaded_file($_FILES['image']['tmp_name'], $target);
echo "<script type='text/javascript'>location.href='?title=$title';</script>";
}
else
{
$message = "Sila pilih semua fail";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
?>
</div>
</form>
</div>
</div>
</div>
</div>
May I know how to view the next image in the modal without it closing ?
Thank you.
I have the following code:
$media = $db->query("SELECT * FROM uploaded_photos WHERE user_id='".$profile->id."' LIMIT 20");
$picheck = $db->query("SELECT * FROM users WHERE id='".$profile->id."'");
$picheck = $picheck->fetch_object();
if($media->num_rows == 0) {
$uploaded_photos = 0;
} else {
$uploaded_photos = array();
while($photo = $media->fetch_object()) {
$photos[] = array('type'=>'uploaded','id' => $photo->id, 'path' => $photo->path);
}
}
//IN A RELATED PHP FILE:
<?php
$c=0;
if(!empty($photos)) {
for($i = 0; $i < count($photos); $i++) {
if($photos[$i]['type'] == 'instagram') {
} else {
$c++;
echo '<div class="col-sm-3 col-md-3 col-lg-3 thumbnail m-5">';
echo '<div class="image-container">';
echo '<img src="'.$system->getDomain().'/uploads/'.$photos[$i]['path'].'" class="img-responsive">';
echo '
<div class="caption">
<h4>';
//HERE IS MY PROBLEM, IF THE PATH OF THE USERS CURRENT PROFILE PHOTO IS THE SAME AS THE PATH OF THE PHOTO DISPLAYED, IT SHOULD ECHO SOMETHING DIFFERENT.
if(in_array($picheck->profile_photo, $photos['path'], true)){ echo ' <i class="fa fa-exclamation" data-toggle="tooltip" data-placement="right" data-title="Your Profilepicture" placeholder="" data-original-title="" title=""></i> ';
}
else { echo ' <i class="fa fa-trash" data-toggle="tooltip" data-placement="right" data-title="'.$lang['Delete_Photo'].'" placeholder="" data-original-title="" title=""></i> ';
}
echo '
<i class="fa fa-user" data-toggle="tooltip" data-placement="left" data-title="'.$lang['Profile_Photo'].'" placeholder="" data-original-title="" title=""></i>
</h4>
</div>
';
echo '</div>';
echo '</div>';
}
}
}
if($c==0) {
echo 'YOU DONT HAVE ANY PICTURES';
}
?>
I have been searching high and low to solve this, I hope someone can help me out. I would like to thank all who put efford in helping me out on this beforehand.
The problem is because of this line,
if(in_array($picheck->profile_photo, $photos['path'], true)){ ...
^^^^^^^^^^^^^^^
The second argument of in_array() function i.e $photos['path'] is wrong because $photos array doesn't have an index named path.
So the correct condition for if block would be,
if(in_array($picheck->profile_photo, $photos[$i], true)){ ...