linking url in an article from php dashboard does not work - php

I have a dashboard designed in php for the client from where he is able to add new stories/articles on the main site using the tiny mce editor, just similar to a joomla article. The problem is that when a url is linked then it appends to the main site for some reason. e.g
http://example.com/"http://careers.virginmedia.com//"
I have tried every format for the url, but doesn't work. Please can someone help me with this.
The following code adds the content
function addSponsoredAd()
{
if(isset($_POST['submit']))
{
$db = new Connection(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$userID = $_SESSION['user']['userID'];
$ID = getNextID('sponsoredAds');
$imgTmp = $_FILES['image']['tmp_name'];
$image = basename(strtolower(str_replace(' ', '-', $_FILES['image']['name'])));
$info = pathinfo($_FILES['image']['name']);
$filename = $image;
$imageFolder = '../mediaLibrary/sponsoredAds/';
$imageDestination = $imageFolder.$filename;
move_uploaded_file($imgTmp, $imageDestination);
$title = $_POST['title'];
$description = $_POST['description'];
$position = $_POST['position'];
$status = $_POST['status'];
$content = $_POST['content'];
$parameters = array(
'table' => 'sponsoredAds',
'fieldsAndValues' => array(
'userID' => $userID,
'title' => $title,
'description' => $description,
'status' => $status,
'position' => $position,
'content'=> $content,
'dateAdded' => datetime()
)
);
$db->insert($parameters);
if($imgTmp != '')
{
$parameters = array(
'table' => 'sponsoredAds',
'fieldsAndValues' => array(
'logo' => $imageDestination
),
'conditions' => 'WHERE ID = "'.$ID.'"'
);
$db->update($parameters);
}
setMessage('Added a new sponsored ad: '.$title, 1);
header('Location: '.BASE_URL.'dashboard/sponsoredAds');
}
}
The code below displays it
function getSponsoredListings()
{
$db = new Connection(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$result = $db->query('
SELECT *
FROM sponsoredAds
ORDER BY position
');
$items='';
while($row = mysql_fetch_assoc($result))
{
$items .= '
<div id="search-results">
<div class="search-result '.$class.'" id="searchResult'.$row['ID'].'">
<a href="sponsored-posts/'.$row['ID'].'">
<div class="img-container">
<img src="'.BASE_URL.str_replace('../', '', $row['logo']).'" alt="'.$row['title'].'" />
</div><!-- End img container -->
<h3>'.$row['title'].'</h3>
<p>'.$row['content'].'</p>
<div class="cont">'.$row['description']
.'</div><!-- End cont -->
</a>
</div><!-- End search result -->
</div><!-- End search results -->
';
$count++;
}
return $items;
}
The tinymce page code:
<head>
<title>Dashboard</title>
<link rel="stylesheet" href="<?php echo BASE_URL; ?>_style/main.css" />
<link rel="stylesheet" href="<?php echo BASE_URL; ?>_style/dashboard.css" />
<link href="<?php echo BASE_URL; ?>favicon.ico" type="image/x-icon" rel="shortcut icon" />
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>-->
<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script src="<?php echo BASE_URL; ?>_scripts/functions.js"></script>
<script src="<?php echo BASE_URL; ?>dashboard/_scripts/functions.js"></script>
<script src="<?php echo BASE_URL; ?>_scripts/notify.1.0.js"></script>
<script src="<?php echo BASE_URL; ?>_scripts/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
<script src="<?php echo BASE_URL; ?>_scripts/jquery.validate.min.js"></script>
<script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
<script src="<?php echo BASE_URL; ?>_scripts/jquery.cookie.js"></script>
<script src="http://cdn.jquerytools.org/1.2.7/all/jquery.tools.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector:'textarea',
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
var BASE_URL = '<?php echo BASE_URL; ?>';
$(document).ready(function() {
$('textarea.tinymce').tinymce({
// Location of TinyMCE script
script_url : '<?php echo BASE_URL; ?>_scripts/tinymce/jscripts/tiny_mce/tiny_mce.js',
mode : 'textareas',
plugins : 'jbimages,paste,fullscreen,media,table',
paste_auto_cleanup_on_paste : true,
theme : 'advanced',
theme_advanced_buttons1 : 'bold,italic,underline,|,bullist,numlist,|,link,unlink,image,jbimages,|,formatselect,removeformat,code, fullscreen, media,|,tablecontrols',
theme_advanced_buttons3_add : "tablecontrols",
table_styles : "Header 1=header1;Header 2=header2;Header 3=header3",
table_cell_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1",
table_row_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1",
table_cell_limit : 100,
table_row_limit : 5,
table_col_limit : 5,
theme_advanced_buttons2 : '',
theme_advanced_buttons3 : '',
theme_advanced_buttons4 : '',
theme_advanced_toolbar_location : 'top',
theme_advanced_toolbar_align : 'left',
theme_advanced_resizing : true,
theme_advanced_blockformats : 'Paragraph=p,Heading=h4,Leading=h3',
relative_urls : false,
valid_elements : '*[*]',
valid_styles : {'span' : 'text-decoration', 'img' : 'vertical-align,border,margin-top,margin-bottom,margin-left,margin-right,float'},
width: '100%',
height: '400',
extended_valid_elements: "embed[width|height|name|flashvars|src|bgcolor|align|play|loop|quality|allowscriptaccess|type|pluginspage]",
media_strict: false
});
$('#name').keyup(function(){
$('#permalink').val($('#name').val().replace(/[^a-zA-Z 0-9-]+/g, '').toLowerCase().replace(/\s/g, '-').replace('--', '-'));
});
});
</script>
<h1>Add a New Sponsored Ad</h1>
<form action="<?php addSponsoredAd(); ?>" method="post" enctype="multipart/form-data">
<label for="image">Logo</label>
<input type="file" name="image" id="image" />
<label for="title">Title</label>
<input type="text" name="title" id="title" />
<label for="description">Description</label>
<textarea name="description" id="description"><?php echo $info['description']; ?></textarea>
<label for="content">Content</label>
<textarea class="tinymce" name="content" id="content"><?php echo $info['content']; ?></textarea>
<!-- <label for="position">Position</label>
<input type="text" name="position" id="position" /> -->
<label for="status"><input type="checkbox" name="status" id="status" value="1" /> Active?</label>
<input type="submit" name="submit" id="submit" value="Add Sponsored Ad" />
</form>

You are using TinyMCE with the relative_urls = false option. From looking at the TinyMCE docs on URL conversion I think you should instead drop that option and add convert_urls: false.

Related

Datagrid Easyui Not Work

Help.
Datagrid EasyUI Not Work
Error :
jquery.easyui.min.js:11286 Uncaught TypeError: Cannot read property 'length' of undefined
at Object.renderTable (jquery.easyui.min.js:11286)
at Object.render (jquery.easyui.min.js:11263)
at _6e1 (jquery.easyui.min.js:10149)
at HTMLTableElement.<anonymous> (jquery.easyui.min.js:11055)
at Function.each (jquery.min.js:2)
at m.fn.init.each (jquery.min.js:2)
at Object.loadData (jquery.easyui.min.js:11054)
at m.fn.init.$.fn.datagrid (jquery.easyui.min.js:10816)
at jquery.easyui.min.js:10770
at Object.success (jquery.easyui.min.js:11526)
Code in : https://pastebin.com/Y2L8UyeV
Controller Pencatatan.php
class Pencatatan extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->model('M_Pencatatan');
}
function index(){
$data['title'] = 'Pencatatan Transaksi';
$data['content'] = 'V_Pencatatan';
$this->load->view('Template/full',$data);
}
function data()
{
$data['datatables'] = $this->M_Pencatatan->show_keuangan_all();
echo json_encode($data);
}
}
Model M_Pencatatan.php
function show_keuangan_all(){
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'id_keuangan';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
$offset = ($page-1) * $rows;
$result = array();
$result['total'] = $this->db->get('keuangan')->num_rows();
$row = array();
$this->db->limit($rows,$offset);
$this->db->order_by($sort,$order);
$criteria = $this->db->get('keuangan');
foreach($criteria->result_array() as $data)
{
$row[] = array(
'id'=>$data['id_user'],
'keterangan'=>$data['keterangan'],
'value'=>$data['value'],
'tanggal'=>$data['tanggal_transaksi']
);
}
$result=array_merge($result,array('rows'=>$row));
return $result;
}
}
Full View
<html>
<head>
<meta charset="UTF-8">
<title>Pencatatan</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>asset/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>asset/themes/icon.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>asset/demo/demo.css">
<script type="text/javascript" src="<?php echo base_url(); ?>asset/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>asset/jquery.easyui.min.js"></script>
<script type="text/javascript">
window.setTimeout("waktu()",1000);
function waktu() {
var tanggal = new Date();
setTimeout("waktu()",1000);
document.getElementById("jam").innerHTML = tanggal.getHours();
document.getElementById("menit").innerHTML = tanggal.getMinutes();
document.getElementById("detik").innerHTML = tanggal.getSeconds();
}
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding-left:5px;padding-right:5px">
<table width="100%">
<tr>
<td style="width:50%;"><font size="5px;" color="#00004d"><b>Pencatatan Keuangan</b></font></td>
<td style="width:50%;" align="right">
</td>
</tr>
<tr>
<td><font size="2px;" color="#7c7c50">Selamat Datang, </font></td>
<td align="right"><font size="3px;" color="#00004d"><b><?php echo date('d F Y'); ?> <Font id="jam" style=""></Font>:
<Font id="menit"></Font>:
<Font id="detik"></Font></b></font></td>
</tr>
</table>
</div>
<div data-options="region:'west',split:true,title:'Main Menu'" style="width:150px;" class="easyui-accordion">
<div title="Transaction" data-options="iconCls:'icon-search'">
<ul class="easyui-tree">
<li>
<span>Transaction</span>
<ul>
<li>
<a style="color:black;text-decoration:none;" href="<?php base_url();?>Pencatatan" data-options="plain:true" onclick="addPencatatan()">Pencatatan</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
<div data-options="region:'south',border:false,split:false" style="height:25px;background:#A9FACD;padding:0px;"><font size="2px;" color="#00004d"><b><center>© Tuyullie</center></b></font></div>
<!-- Sub Main -->
<div data-options="region:'center',title:'Web Dashboard'">
<div id="tt" class="easyui-tabs" data-options="tools:'#tab-tools'" style="width:100%;height:100%">
<?php if(isset($content)) {$this->load->view($content);} ?>
</div>
</div>
<script type="text/javascript">
function addPencatatan(){
$('#tt').tabs('add',{
title: 'Pencatatan',
closable: true
});
}
</script>
<!-- End Sub Main -->
</body>
</html>
V_Pencatatan.php View
<table id="dg"></table>
<!-- Toolbar -->
<div id="toolbar">
</div>
<script>
$(document).ready(function(){
$('#dg').datagrid({
border: false,
title: "Pencatatan",
fit: true,
class: "easyui-datagrid",
pagination: true,
pageSize: 50,
striped: true,
sortName: "id_user",
sortOrder: "desc",
pageList: [50, 100, 150, 200, 250],
rownumbers: true,
fitColumns: true,
singleSelect: true,
url:'Pencatatan/data',
columns:[[
{field:'id',tittle:'ID',width:100},
{field:'keterangan',tittle:'Keterangan',width:100},
{field:'value',tittle:'Value',width:100},
{field:'tanggal',tittle:'Tanggal',width:100}
]]
})
})
</script>

Angular JS posting image and hidden field data to php

I am facing a problem in accessing the value of hidden field.
I have made an image cropping application in which i am asking the user to upload an image and a UI is provided to help the user to select the area to crop. Then the top left x and y coordinate and the width and height of the selected area is stored as a semicolon separated string in a hidden input field and when the 'Crop' button is clicked the image and the hidden filed value is passed to the crop.php file. But the values of the hidden field is not accessible in the php file.
My html file which provides browse and crop functionality -
<!doctype html>
<html>
<head>
<title>
Crop
</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js"></script>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
<script>
var app = angular.module('main-App',[]);
app.controller('AdminController', function($scope, $http) {
$scope.form = [];
$scope.files = [];
$scope.progressBar=0;
$scope.progressCounter=0;
$scope.submit = function() {
alert('Sub');
$scope.form.image = $scope.files[0];
$http({
method : 'POST',
url : 'crop.php',
processData: false,
transformRequest: function (data) {
var formData = new FormData();
formData.append("image", $scope.form.image);
return formData;
},
data : $scope.form,
headers: {
'Content-Type': undefined
},
uploadEventHandlers: {
progress: function (e) {
if (e.lengthComputable) {
$scope.progressBar = (e.loaded / e.total) * 100;
$scope.progressCounter = $scope.progressBar;
$("#completion").css("width", $scope.progressBar+'%');
}
}
}
}).then(function successCallback(response) {
alert($scope.form.params);
});
};
$scope.uploadedFile = function(element) {
$scope.currentFile = element.files[0];
var reader = new FileReader();
reader.onload = function(event) {
$scope.image_source = event.target.result
$scope.$apply(function($scope) {
$scope.files = element.files;
});
}
reader.readAsDataURL(element.files[0]);
$('img#photo').imgAreaSelect({
onSelectStart: {enable:true},
onSelectEnd: function (img, selection) {
document.getElementById("params").value=selection.x1+';'+selection.y1+';'+selection.width+';'+selection.height;
alert(document.getElementById("params").value);
}
});
}
});
</script>
<style>
html,body {
height: 100%;
}
.wrapper{
height:auto;
}
.wrapper img {
height:100%;
color:grey;
text-align: center;
line-height:100px;
vertical-align: middle;
padding:0px;
margin:0px;
}
</style>
</head>
<body>
<div ng-app="main-App" ng-controller="AdminController">
<form ng-submit="submit()" name="form" role="form" enctype="multipart/form-data">
<div class="container-fluid">
<div class="row flex-items-xs-center">
<div class="col-md-9">
<div class="container-fluid">
<div class="row">
<div class="col-md-9">
<div class="wrapper">
<img id="photo" name="photo" src="{{image_source}}" alt="Image preview..." class="img-responsive img-thumbnail" style="border-style:dashed">
</div>
</div>
</div>
</div>
<br/>
<br/>
<div class="container-fluid">
<div class="row">
<div class="col-md-2">
<label class="btn btn-primary">
<input ng-model="form.image" type="file" class="form-control input-lg" name="image" id="image"
accept = "image/*"
onchange="angular.element(this).scope().uploadedFile(this)"
style="display:none;" >
<span class="glyphicon glyphicon-folder-open"></span>
Browse
</label>
</div>
<div class="col-md-2">
<label class="btn btn-success">
<input type="submit" id="submit" value="Submit" style="display:none;"/>
<span class="glyphicon glyphicon-cloud-upload"></span>
Crop
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<input type="hidden" name="params" id="params" value="0;0;0;0" ng-model="params" />
</form>
<br/>
<br/>
<div class="container-fluid">
<div class="row">
<div class="col-md-9">
<div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" id ="completion" name="completion"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="50" style="width:0%;height:10px;border-width:0px;border-radius:2px;">
</div>
</div>
</div>
</div>
</div>
<br/>
<br/>
the UI -
crop.php -
<?php
$uncropped_path = '/var/www/html/images/original/';
$cropped_path = '/var/www/html/images/cropped/';
if(isset($_FILES['image'])){
//$ext = pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION);
$image = $_FILES['image']['name'];
move_uploaded_file($_FILES["image"]["tmp_name"], $uncropped_path.$image);
$data = json_decode(file_get_contents("php://input"));
print_r($data);
}else{
echo "Image Is Empty";
}
function doResize($filename,$size,$resize_path)
{
$image = new Imagick();
$file = file_get_contents($filename);
$image->readImageBlob($file);
$dimensions = $image->getImageGeometry();
$pathInfo = pathinfo($filename);
$name = $pathInfo['filename'];
$srcWidth = $dimensions['width'];
$srcHeight = $dimensions['height'];
list($resWidth,$resHeight) = getResizeDim($size,$srcWidth,$srcHeight);
$image->resizeImage($resWidth,$resHeight,Imagick::FILTER_LANCZOS,.85);
$image->writeImage($resize_path);
}
function getResizeDim($size,$srcWidth,$srcHeight)
{
$width;
$height;
if($srcHeight > $srcWidth)
{
if($srcHeight > $size)
$height = $size;
else $height = $srcHeight;
$width = ceil($height*($srcWidth/$srcHeight));
}
else {
if($srcWidth > $size)
$width = $size;
else $width = $srcWidth;
$height = ceil($width*($srcHeight/$srcWidth));
}
return array($width,$height);
}
When i try to print the data received in php i get the following -
Moreover the data array in the php seems to be empty.
I have read various similar questions on stackoverflow but none of them worked in my case.

Code is not creating a file in server directory php

Im trying to write a new file to the server using the following code
error_reporting(E_ALL); ini_set('display_errors', 1);
if($_SERVER['REQUEST_METHOD'] == "POST") {
$html = $_POST['html'];
$filename = $_POST['fileName'];
$file = fopen('"$filename".php', 'w');
fwrite($file, $html);
// fwrite($file, $_POST["cssContent"]);
fclose($file);
The file being created is a new html page and the html content is being copied using jquery post, in the echo statements I can see the html is there as well as the filename I would like to call this new file, however after the script is run the file hasn't been created and the php error report is not reporting an error. The $file echo shows the file as Resource id #3
The html page code
<?php
include_once '../../../includes/db_connect.php';
include_once '../../../includes/functions.php';
sec_session_start();
error_reporting(E_ALL); ini_set('display_errors', 1);
$first_name = $_SESSION['memberInfo']['memberFirstName'];
$surname = $_SESSION['memberInfo']['memberLastName'];
$hash = $_SESSION['memberInfo']['hash'];
$newTemplateSrc = $_SESSION['memberInfo']['templateSrc'];
$sql = "SELECT * FROM members WHERE firstName = '$first_name' AND surName = '$surname' AND passWord = '$hash' AND templateFileSrc = '$newTemplateSrc'";
$result=mysqli_query($mysqli, $sql);
while($row = mysqli_fetch_array($result) ){
$dateofBirth = $row['dateofBirth'];
$deceasedName = $row['deceasedName'];
$dateofDeath = $row['dateofDeath'];
$aboutDeceased = $row['aboutDescription'];
$directoryId = $row['directoryid'];
$templateFileSrc = $row['templateFileSrc'];
$deceasedImage = $row['deceasedPhoto'];
};
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- TemplateBeginEditable name="doctitle" -->
<title>RIDERS in the SKY CREATE MEMORIAL</title>
<!-- TemplateEndEditable -->
<link rel="stylesheet" type="text/css" href="../../../style/rits2.css">
<link rel="stylesheet" type="text/css" href="../../../Valums-File-Uploader-file-uploader-9991748/client/fileuploader.css">
<style type="text/css">
a:link {
text-decoration: none;
color: rgba(135,206,235,1);
}
a:visited {
text-decoration: none;
color: rgba(135,206,235,1);
}
a:hover {
text-decoration: none;
color: rgba(0,0,0,1);
}
a:active {
text-decoration: none;
color: rgba(135,206,235,1);
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>
<body>
<div class="container">
<header>
<table id="head_top">
<tbody>
<tr>
<td width="10%" rowspan="3" class="logo"><img src="../../../images/riders-in-the-sky.png" alt="RIDERS IN THE SKY LOGO - CLICKING HERE TAKES YOU TO THE HOME PAGE" title="RIDERS IN THE SKY LOGO - CLICKING HERE TAKES YOU TO THE HOME PAGE" class="logo_image"/></td>
<td width="80%" colspan="3" class="title">RIDERS IN THE SKY </td>
<td width="10%" rowspan="3" class="login_register"><table class="log_nav">
<tbody>
<tr>
<td><form action="../../../register.php"><input name="register" type="submit" class="register" title="REGISTER HERE" id="register" value="Register"></form></td>
</tr>
<tr>
<td><form action="../../../login.php"><input name="login" type="submit" class="login" title="LOGIN HERE" id="login" value="Login"></form>
</td>
</tr>
<tr> </tr>
</tbody>
</table></td>
</tr>
<tr>
<td colspan="3" class="title_tagline">MEMORIALS AND FUNERAL RESOURCES FOR BIKERS AND MOTORCYCLISTS</td>
</tr>
<tr>
<td><div class="3but_nav volunteer">VOLUNTEER</div></td>
<td><div class="3but_nav resource hover">FUNERAL RESOURCES</div></td>
<td><div class="3but_nav about">ABOUT US</div></td>
</tr>
</tbody>
</table>
<table class="top_nav">
<tbody>
<tr>
<td class="create"><form><input name="create" type="button" class="create_but" id="create" value="Create Memorial" title="CTREATE A MEMORIAL HERE" onClick="window.location.href='../../../create.php'"></form></td>
<td class="view"><form><input name="view" type="button" class="view_but" id="view" value="View Memorials" title="VIEW A MEMORIAL HERE" onClick="window.location.href='../../../view.php'"></form></td>
<td class="faq"><form><input name="faq" type="button" class="faq_but" id="faq" value="Faq's" title="GO TO OUR FAQ's and HELP PAGE" onClick="window.location.href='../../../faq.php'"></form></td>
<td class="contact"><form><input name="contact" type="button" class="contact_but" id="contact" value="Contact Us" title="NEED TO CONTACT US? CONTACT US HERE" onClick="window.location.href='../../../contact.php'"></form></td>
<td class="donate"><form><input name="donate" type="button" class="donate_but" id="donate" value="Make a Donation" title="WANT TO MAKE A DONATION TO RIDERSin the SKY? GO TO OUR DONATIONS PAGE" onClick="window.location.href='../../../donation.php'"></form></td>
</tr>
</tbody>
</table>
</header>
<!-- TemplateBeginEditable name="content_main" -->
<main class="content">
<div id="deceasedName" class="#" contenteditable="false"><?php echo $deceasedName ?></div>
<div id="DeceasedDetail" contenteditable="false">
<div id="dob" contenteditable="false"><?php echo $dateofBirth ?></div>
<div id="deceasedImage" contenteditable="false"><img class="deceasedImage" src="<?php echo $deceasedImage ?>"></div>
<div id="dod" contenteditable="false"><?php echo $dateofDeath ?></div>
<div id="deceasedProfile">
<h1 id="aboutTitle" contenteditable="false" >About <?php echo $deceasedName?></h1>
<h2 id="aboutDesciption" contenteditable="false" ><?php echo $aboutDeceased ?></h2>
</div>
<input name="button" type="button" class="editMemorial" value="Edit/Create Memorial">
</div>
<div class="editMenu" style="display:none">
<button id="editDOB" class="editMenuNav">Edit/Add D.O.B</button>
<button id="editPic" class="editMenuNav">Change/Add Deceased Photo</button>
<button id="editDOD" class="editMenuNav">Edit/Add Deceased D.O.D</button>
<button id="editDeceasedTitle" class="editMenuNav">Edit/Add About the Deceased Title</button>
<button id="editDeceasedDescription" class="editMenuNav">Edit/Add About the Deceased</button>
<button id="editName" class="editMenuNav">Edit/Add Deceased Name</button>
<button id="saveEdits" class="editMenuNav">Save Changes</button>
</div>
</main>
<!-- TemplateEndEditable -->
<footer class="footer">
<div class="breadcrumb">
<p class="breadcrumb">Funeral Resources | Terms of Use | Privacy | About Us | Contact Us | Faq's</p>
<p class="copyright"><span>©2015 RIDERS IN THE SKY</span></p>
</div>
</footer>
</div>
<div id="uploadDeceasedImage" style="display: none">
<div id="closeDeceasedUpload">Close Upload X</div>
<noscript>
<p>Please enable JavaScript to use file uploader.</p>
or put a simple form for upload here
</noscript>
<div id="preview">
<img src="../../../images/riders in the sky no text.png" alt="" width="100px" height="100px" class="deceasedThumb"/>
</div>
<!--<form id="deceasedImageUpload">
<label class="deceasupload">Upload a Picture of the Deceased</label>
<input type="file" size="20" id="imageUpload" class=" ">
<button type="submit" class="saveDeceasedImage">Save Photo</button>
</form>-->
<div id="uploadDeceasedImageWrapper">
</div>
<input id="file_upload" name="file_upload" type="file" multiple style="display:none">
<input type="button" id="upload_but" href="javascript:$('#file_upload').uploadifive('upload')" style="display: none" value="Upload Images">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../../../Valums-File-Uploader-file-uploader-9991748/client/fileuploader.js"></script>
<script type="text/javascript">
$(".editMemorial").on('click', function() {
$('.editMenu').show();
$('.editMemorial').hide();
});
$("#saveEdits").on('click', function() {
var dateofBirth = ($('#dob').text());
var deceasedName = ($('#deceasedName').text());
var dateofDeath = ($('#dod').text());
var aboutTitle = ($('#aboutTitle').text());
var aboutDescription = ($('#aboutDesciption').text());
var firstName = ("<?php echo $first_name?>");
var surName = ("<?php echo $surname?>");
var hash = ("<?php echo $hash?>");
var templateSrc = ("<?php echo $newTemplateSrc?>");
// console.log(dateofBirth, deceasedName, dateofDeath, abouttheDeceased,firstName, surName, hash, templateSrc);
$.post('../../../includes/editContent.php', {dateofBirth:dateofBirth,deceasedName:deceasedName,dateofDeath:dateofDeath, aboutTitle:aboutTitle,aboutDescription:aboutDescription,firstName:firstName,surName:surName,hash:hash,templateSrc:templateSrc }, function(json) {
if(json.result === "success") {
$('.editMenu').hide();
$('.editMemorial').show();
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'false');
$('#dob').attr('class','#')
$('#dod').attr('class','#')
$('#aboutDesciption').attr('class','#')
$('#aboutTitle').attr('class','#')
$('#deceasedName').attr('class','#')
$('#uploadDeceasedImage').hide();
}else{
};
});//json call
});//onclick
// editable clicks
$("#editDOB").on('click', function() {
$('#dob').attr('contenteditable', 'true');
$('#dod').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'false');
$('#dob').attr('class','deceasedNameHighlight');
$('#dod').attr('class','#');
$('#deceasedName').attr('class','#');
$('#aboutDesciption').attr('class','#');
$('#aboutTitle').attr('class','#');
$('#uploadDeceasedImage').hide();
});
$("#editName").on('click', function() {
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'true');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'false');
$('#dob').attr('class','#');
$('#dod').attr('class','#');
$('#deceasedName').attr('class','deceasedNameHighlight');
$('#aboutDesciption').attr('class','#');
$('#aboutTitle').attr('class','#');
$('#uploadDeceasedImage').hide();
});
$("#editDOD").on('click', function() {
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'true');
$('#deceasedName').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'false');
$('#dob').attr('class','#');
$('#dod').attr('class','deceasedNameHighlight');
$('#deceasedName').attr('class','#');
$('#aboutDesciption').attr('class','#');
$('#aboutTitle').attr('class','#');
$('#uploadDeceasedImage').hide();
});
$("#editDeceasedDescription").on('click', function() {
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'true');
$('#aboutTitle').attr('contenteditable', 'false');
$('#dob').attr('class','#');
$('#dod').attr('class','#');
$('#deceasedName').attr('class','#');
$('#aboutDesciption').attr('class','deceasedNameHighlight');
$('#aboutTitle').attr('class','#');
$('#uploadDeceasedImage').hide();
});
$("#editDeceasedTitle").on('click', function() {
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'true');
$('#dob').attr('class','#');
$('#dod').attr('class','#');
$('#deceasedName').attr('class','#');
$('#aboutDesciption').attr('class','#');
$('#aboutTitle').attr('class','deceasedNameHighlight');
$('#uploadDeceasedImage').hide();
});
$('#editPic').on('click', function() {
$('#uploadDeceasedImage').show();
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'false');
$('#dob').attr('class','#');
$('#dod').attr('class','#');
$('#deceasedName').attr('class','#');
$('#aboutDesciption').attr('class','#');
$('#aboutTitle').attr('class','#');
});
$('#closeDeceasedUpload').on('click', function() {
$('#uploadDeceasedImage').hide();
$('#dob').attr('contenteditable', 'false');
$('#dod').attr('contenteditable', 'false');
$('#deceasedName').attr('contenteditable', 'false');
$('#aboutDesciption').attr('contenteditable', 'false');
$('#aboutTitle').attr('contenteditable', 'false');
$('#dob').attr('class','#');
$('#dod').attr('class','#');
$('#deceasedName').attr('class','#');
$('#aboutDesciption').attr('class','#');
$('#aboutTitle').attr('class','#');
});
</script>
<script type="text/javascript">
// DOM-ready event is a much option here, just using onload in demo for simplicity
// jQuery users can use $(function()) { ...
window.onload = function() {
var uploader = new qq.FileUploader({
// pass the dom node (ex. $(selector)[0] for jQuery users)
element: document.getElementById('uploadDeceasedImageWrapper'),
// path to server-side upload script
// action: '/server/upload'
action: '../../../includes/uploadDeceased_image.php',
params: {
directoryId: '<?php echo $directoryId ?>',
templateSrc: '<?php echo $templateFileSrc ?>'
},
allowedExtensions: ['jpg', 'png'],
sizeLimit: 100000000, // 100mb
minSizeLimit: 500,
debug: true
});
};
</script>
<script type="text/javascript">
$('#saveEdits').on('click', function() {
var html = $("html").html();
var fileName = <?php echo $directoryId ?>;
console.log(html);
$.post('../../../includes/memorialSave.php', {html:html, fileName:fileName}, function(json) {
});
});
</script>
</body>
</html>
The html and filename are being sent to the php by the jquery code as shown below
<script type="text/javascript">
$('#saveEdits').on('click', function() {
var html = $("html").html();
var fileName = <?php echo $directoryId ?>;
console.log(html);
$.post('../../../includes/memorialSave.php', {html:html, fileName:fileName}, function(json) {
});
});
</script>
I'm aware that there is a lot of jquery that could be better scripted but I'm new to jquery and initially I'm just getting stuff to work
I see $filename = $_POST['fileName']; and that tells me we're dealing with files.
Sidenote: fileName and filename are not the same, should that be the case for the input.
This also tells me you're using a form and wanting to upload a file.
Since you have not provided the rest of the code, your form needs to have a POST method, including a valid enctype.
I.e. method="post" enctype="multipart/form-data". Make sure that's included.
This $filename = $_POST['fileName']; will need to be changed to
$filename = $_FILES['fileName']; while making sure the input for it also bears the fileName name attribute.
Make sure your form contains the POST method.
Forms default to GET if omitted <form action=""> and will fail silently.
While doing <form action="" method="post"> will specify it exactly.
Also $file = fopen('"$filename".php', 'w');
quotes are wrong which should be
$file = fopen($filename.".php", 'w');
or simply $file = fopen($filename, 'w'); - unsure what the file is to be.
Post the rest of your code in order to be sure.
If I'm wrong here, I'll just delete this.
Edit: Test.
Using the following test code, worked for me and created a file called filename1.php with "content" inside it.
$_POST['html'] = "content";
$_POST['fileName'] = "filename1";
$html = $_POST['html'];
$filename = $_POST['fileName'];
$file = fopen($filename.".php", 'w');
As did
$_POST['html'] = "<b>content</b>"; with <b>content</b> inside it.
2nd edit:
The $file echo shows the file as Resource id #3
You haven't shown us where you're trying to pull that content/file from.
Answer/example pulled from: https://stackoverflow.com/a/2408630/
The file did open just fine, you cannot echo it like that because it's a file pointer, not the contents of the file itself. You need to use fread() to read the actual contents, or better yet, use file_get_contents() the get the content straight away.
Doing it your way:
$handle = fopen("test.txt", "r");
$fileip = fread($handle, filesize($filename));
fclose($handle);
echo $fileip;
Or, using file_get_contents():
$fileip = file_get_contents("test.txt");
echo $fileip;
Path example:
$path = "/var/user/home/httpdocs/folder_to_write_in/";
$file = fopen($path.$filename.".php", 'w');
PHP will only parse variable within double quotes, so in your case you need to do this:
$file = fopen("\"$filename\".php", 'w');
or
$file = fopen($filename.'.php', 'w');
also you need to make sure PHP has enough permission to create file
Error in quotes it would be
$file = fopen($filename.".php", 'w');
Also read this single quotes vs double quotes
For examlpe
$filename = "text.php";
echo '$filename'; // $filename.
echo "$filename"; // text.php.

Trying to show jqmobile grid(trirand) in a jquery mobile windows

Using JQuery Mobile I want to pop a dialog box where the user can enter in search filters and then when they submit the query show the jqmobile grid(trirand) inside a modal window. Is this possible. Here is my code below:
qr.php
<?php require_once '../auth.php'; require_once '../jqSuitePHP/jq-config.php'; // include the PDO driver class require_once '../../jqSuitePHP/php/jqGridPdo.php'; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); if(isset($_REQUEST['a'])) { //get asset information $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); $sql = "SELECT asset_no, dept_id as dept, short_desc, `LOTO #` as loto FROM mfg_eng_common.machine WHERE asset_no ='".$_REQUEST['a']."'"; $result = $conn->query($sql); $row = $result->fetch(PDO::FETCH_ASSOC); //check to see if active work order exists in MWO system for current asset //status_id of 50 mean Approved/Closed $sql = "SELECT count(*) woCnt FROM mfg_eng_mwo.mwo WHERE asset_id ='".$_REQUEST['a']."' AND status_id != 50"; $result = $conn->query($sql); $woCnt = $result->fetch(PDO::FETCH_ASSOC); } else { header("Location: http://rworley-laptop.dayton-phoenix.com/dpg/mwo/forms/MWO.php"); } ?> <!DOCTYPE HTML> <html lang="en-US"> <head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> <script type="text/javascript"> function getWOCnt() { var cntval = <?php echo $woCnt['woCnt'];?>; if(cntval > 0) { if (confirm(" There are already active work order(s) for asset <?php echo $_REQUEST['a']?>. \n To see active work orders:\n Click Cancel and then click 'Update Work Orders'. \n\n To enter a new work order for asset <?php echo $_REQUEST['a']?> \n Click OK .")) { window.open("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>", "new"); /* $(function () { $("#newMWO").on('click', (function (event) { event.preventDefault(); var loadVars=(encodeURI("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>")); var dialogName= $("#mwoForm").load(loadVars); $(dialogName).dialog({ autoOpen: false, resizable: true, modal: true, bigframe: true, height: 600, width: 1000, overflow: scroll, resizable: true, title: "MWO New Work Order" }); dialogName.dialog('open'); return false; })); }); */ } } else { window.open("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>", "new"); /* $(function () { $("#newMWO").on('click', (function (event) { event.preventDefault(); var loadVars=(encodeURI("../forms/MWO.php?a=<?php echo $_REQUEST['a']?>")); var dialogName= $("#mwoForm").load(loadVars); $(dialogName).dialog({ autoOpen: false, resizable: true, modal: true, bigframe: true, height: 600, width: 1000, overflow: scroll, resizable: true, title: "MWO New Work Order" }); dialogName.dialog('open'); return false; })); }); */ } }; </script> </head> <body> <div data-role="page" data-theme="b" align="center"> <div data-theme="a" data-role="header"> <h1>Maintenance Work Orders</h1> <img alt="<?php echo $_REQUEST['a']?>" src="../../Machine Pictures/<?php echo $row['dept']?>/<?php echo $row['asset_no']?>.jpg" height="240" width="300"/> <b><br><?php echo $row['short_desc']?></b> </div><!-- /header --> <br> <div data-theme="c" data-content-theme="d" > <hr> <?php echo "PM Procedure" ?> <b>|</b> <?php echo "Loto Procedure" ?> </div> <div data-role="collapsible-set" data-theme="b" data-content-theme="d" > <ul data-role="listview" data-inset="true" align="center" data-filter="false" data-theme="b"> <li> <a id="newMWO" name="newMWO" data-role="button" data-inline="true" target="_blank" onclick=getWOCnt() > New Work Order </a> </li> </ul> <ul data-role="listview" data-inset="true" align="center" data-filter="false" data-theme="b"> <li> Update Work Order </li> </ul> <ul data-role="listview" data-inset="true" align="center" data-filter="false" data-theme="b"> <li> <a href="../../mwo/MWO_mobile.php?a=<?php echo $_REQUEST['a']?>" data-role="button" data-inline="true" data-rel="dialog" target="mwoSearch" data-transition="slidedown" > Search Work Orders </a> </li> </ul> </div> <?php if(!($_POST)) { echo " <a href='#popupBasic' data-rel='popup' data-role='button' data-inline='true'>Quick Search</a> <div data-role='popup' id='popupBasic' data-transition='flip' > <a href='#' data-rel='back' data-role='button' data-theme='a' data-icon='delete' data-iconpos='notext' class='ui-btn-right'>Close</a> <form action='#' method='POST'> <div data-theme='a' data-role='header'> <h2>Look Up MWO</h2> </div> <p> Problem<textarea name='search_prob' data-theme = 'a' data-content-theme = 'd' rows = '3' cols = '50' id = 'search_prob' /></textarea> </p> <p> Solution<textarea name='search_sol' data-theme = 'a' data-content-theme = 'd' rows = '3' cols = '50' id = 'search_sol' /></textarea> </p> <p id = 'submit-area'> <input type='submit' data-theme='b' value='Search' id = 'sub1'/> </p> </form> </div> "; } else { echo " <ul data-role='listview' data-inset='true' align='center' data-filter='false' data-theme='b'> <li> <a href=\"QS.php?a=".$_REQUEST['a']."\" data-role='button' data-inline='true' data-rel='dialog' data-transition='slidedown'> Qucick Search Results </a> </li> </ul>"; } ?> <div data-role="footer" data-theme="a"> <h4>Dayton-Phoenix Group, Inc.</h4> </div><!-- footer --> </div><!-- page --> </body> </html>
QS.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MWO Quick Search</title>
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/ui.jqgridmobile.css" />
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/shCoreEclipse.css" />
<link rel="stylesheet" href="../../jquerymobile.jqGrid/css/themes/shThemeEclipse.css" />
<script src="../../jquerymobile.jqGrid/js/jquery.js" type="text/javascript"></script>
<script src="../../jquerymobile.jqGrid/js/jquerymobile.jqGrid.min.js" type="text/javascript"></script>
<script src="../../jquerymobile.jqGrid/js/jquery.mobile.js" type="text/javascript"></script>
<script src="../../jquerymobile.jqGrid/js/grid.locale-en.js" type="text/javascript"></script>
</head>
<body>
Paging, sorting and searching
</body>
</html>
quickSearch2.php
<!DOCTYPE html>
<html>
<body>
<div id="page" data-role="page" data-theme="b">
<div data-role="header" data-theme="b" style="margin-bottom: 10px">
<h1> MWO Quick Search Results</h1>
Home
</div>
<!-- HTML table Definition -->
<table id='grid'></table>
<div id='pager'></div>
<!-- Java Scruipt Code -->
<script type='text/javascript'>
var a = <?php echo json_encode($_REQUEST['a']); ?>;
var prob = <?php echo json_encode($_REQUEST['search_prob']); ?>;
jQuery('#grid').jqGrid({
"hoverrows":false,
"viewrecords":true,
//"jsonReader":{"repeatitems":false,"subgrid":{"repeatitems":false}},
"gridview":true,
"url":"../../mwo/mobile/quicksearch.php?a=" + a + "&search_prob=" + prob,
"loadonce": true,
"rowNum":10,
"height":200,
"autowidth":true,
"sortname":"mwo_id",
"rowList":[10,30,40],
"datatype":"json",
"colModel":[
{"name":"e", "index":"empty", "sorttype":"int", "hidden":true,"width":50,"editable":true},
{"name":"MWO #", "index":"mwo_id", "sorttype":"int", "key":true,"width":80,"editable":true},
{"name":"DPG #", "index":"asset_id", "sorttype":"string", "width":80, "editable":true},
{"name":"Assigned to", "index":"assigned_id", "sorttype":"string", "width":80, "editable":true},
{"name":"Entered", "index":"entered_time", "sorttype":"datetime", "width":80, "editable":true,"datefmt":"m/d/Y", "searchoptions":{sopt:['eq']}, "formatter":"date","formatoptions":{"srcformat":"Y-m-d H:i:s","newformat":"m/d/Y"}},
{"name":"Problem", "index":"long_desc", "sorttype":"string", "width":80, "editable":true},
{"name":"Solution", "index":"solution", "sorttype":"string", "width":80, "editable":true}
],
"pager":"#pager"
});
</script>
</div>
</body>
</html>
json data being used:
{"page":1,"total":2,"records":13,"rows":[{"mwo_id":"1302271211","cell":["","1302271211","38315","-1","2013-07-08 11:13:19","approved test",""]},{"mwo_id":"1302271213","cell":["","1302271213","38315","-1","2013-07-11 09:26:26","yo momma is so fattest","how fat is she? she's so fat she left the house in heels and came back in flip-flops"]},{"mwo_id":"1302271214","cell":["","1302271214","38315","-1","2013-07-12 12:13:55","july test",""]},{"mwo_id":"1302271215","cell":["","1302271215","38315","-1","2013-07-08 08:59:56","test","update2"]},{"mwo_id":"1302271216","cell":["","1302271216","38315","-1","2013-07-09 06:14:02","test",""]},{"mwo_id":"1302271217","cell":["","1302271217","38315","-1","2013-07-08 09:01:30","yep testing","no answer yet"]},{"mwo_id":"1302271218","cell":["","1302271218","38315","-1","2013-07-09 09:59:46","new test of email system",""]},{"mwo_id":"1302271219","cell":["","1302271219","38315","","2013-07-08 12:33:09","email new test",""]},{"mwo_id":"1302271221","cell":["","1302271221","38315","12","2013-07-11 13:20:55","ANOTHER TEST OF NEW ...WITH EMAIL","AND THE ANSWER IS ....."]},{"mwo_id":"1302271222","cell":["","1302271222","38315","","2013-07-11 09:29:58","test...add issue",""]},{"mwo_id":"1302271223","cell":["","1302271223","38315","","2013-07-11 13:11:15","testing",""]},{"mwo_id":"1302271224","cell":["","1302271224","38315","7","2013-07-11 13:27:32","test with auto assign","no solution its all good"]},{"mwo_id":"1302271226","cell":["","1302271226","38315","7","2013-07-12 12:05:02","Meeting test",""]}]}

Name being inserted, but file is not being uploaded [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I've an upload input field in a form. the problem that the name of the file is being inserted in the database but the file is not being uploaded to the server, and the same code is working on the same server in a different file in the same directory but in a different query. form is set to enctype="multipart/form-data",
here is the code where its not working
<!DOCTYPE html>
<html lang="en">
<head>
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/dbc.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in(); ?>
<?php find_selected_post(); ?>
<?php
$target = "../upload/";
$target = $target . basename( $_FILES['post_photo']['name']);
if (intval($_GET['cat']) == 0) {
redirect_to('cat_posts.php');
}
include_once("includes/form_functions.php");
if (isset($_POST['submit'])) {
$errors = array();
$required_fields = array('post_title', 'position', 'visible', 'post_content');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('post_title' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
$category_id = mysql_prep($_GET['cat']);
$post_title = trim(mysql_prep($_POST['post_title']));
$post_content = mysql_prep($_POST['post_content']);
$post_description = mysql_prep($_POST['post_description']);
$post_keywords = mysql_prep($_POST['post_keywords']);
$post_tags = mysql_prep($_POST['post_tags']);
$post_photo =($_FILES['post_photo']['name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
if (empty($errors)) {
$query = "INSERT INTO ss_posts (
post_title, post_content, post_description, post_keywords, post_tags, post_photo, position, visible, category_id
) VALUES (
'{$post_title}', '{$post_content}', '{$post_description}', '{$post_keywords}', '{$post_tags}', '{$post_photo}', {$position}, {$visible}, {$category_id}
)";
if ($result = mysql_query($query, $connection)) {
$message = "Successfully Created.";
$new_post_id = mysql_insert_id();
redirect_to("cat_posts.php?post={$new_post_id}");
} else {
$message = "The Post Could Not Be Created.";
$message .= "<br />" . mysql_error();
}
} else {
if (count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
}
}
?>
<?php
error_reporting(E_ALL);
echo "<pre>";
print_r($_FILES);
echo "</pre>";
echo "<br/>target: " . $target;
if (!move_uploaded_file($_FILES['post_photo']['tmp_name'], $target)) {
echo "<br/>Upload failed.";
} else {
echo "<br/>Upload done.";
}
?>
<meta charset="utf-8"/>
<title>New Post - Administration Panel</title>
<script src="js/ckeditor/ckeditor.js" type="text/javascript"></script>
<link rel="stylesheet" href="js/ckeditor/sample.css">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/form.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/button.css" type="text/css" media="screen" /> <!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/hideshow.js" type="text/javascript"></script>
<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.equalHeight.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".tablesorter").tablesorter();
}
);
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
</script>
<script type="text/javascript">
$(function(){
$('.column').equalHeight();
});
</script>
</head>
<body>
<header id="header">
<hgroup>
<h1 class="site_title">Administration Panel</h1>
<h2 class="section_title">New Post</h2><div class="btn_view_site">
View Site</div>
</hgroup>
</header>
<!-- end of header bar -->
<section id="secondary_bar">
<div class="user">
<p>Hello, <?php echo $_SESSION['username']; ?> (Logout)</p>
</div>
<div class="breadcrumbs_container">
<article class="breadcrumbs">Administration Panel
<div class="breadcrumb_divider"></div>
<a class="current">New Post</a></article>
</div>
</section>
<!-- end of secondary bar -->
<aside id="sidebar" class="column" style="height:160%;">
<hr/>
<h3>Pages</h3>
<ul class="toggle">
<li class="icn_new_article">Add a New Page</li>
<li class="icn_edit_article">Edit/Delete a Page</li>
</ul>
<hr/>
<h3>Users</h3>
<ul class="toggle">
<li class="icn_add_user">Add New User</li>
<li class="icn_view_users">View Users</li>
</ul>
<hr/>
<h3>Blog</h3>
<ul class="toggle">
<li class="icn_categories">Create a Category</li>
<li class="icn_new_article">Create/Edit a Post</li>
<li class="icn_settings">Home Blog Settings</li>
<li class="icn_settings">Blog Settings</li>
</ul>
<hr/>
<h3>Settings</h3>
<ul class="toggle">
<li class="icn_settings">Settings</li>
<li class="icn_settings">Site Logo</li>
<li class="icn_jump_back">Logout</li>
</ul>
<footer>
<hr />
<p><strong>Copyright © 2013 Sky Define</strong></p>
<p>Powered by Sky Define</p>
</br>
</br>
</footer>
</aside><!-- end of sidebar -->
<section id="main" class="column">
<?php
move_uploaded_file($_FILES['post_photo']['tmp_name'], $target);
// output a list of the fields that had errors
if (!empty($errors)) {
echo "<p class=\"errors\">";
echo "Please review the following fields:<br />";
foreach($errors as $error) {
echo " - " . $error . "<br />";
}
echo "</p>";
}
?>
<article class="module width_full">
<header><h3>New Post</h3></header>
<div class="module_content">
<h2>Adding New Post</h2>
<?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>
<div class="mws-panel grid_4">
<div class="mws-panel-header">
</div>
<div class="mws-panel-body">
<form class="mws-form" enctype="multipart/form-data" action="new_post.php?cat=<?php echo $sel_category['id']; ?>" method="post">
<div class="mws-form-inline">
<?php $new_post = true; ?>
<?php if (!isset($new_post)) {$new_post = false;} ?>
<div class="mws-form-row">
<label>Post Name:</label>
<div class="mws-form-item large">
<input type="text" name="post_title" id="post_title" class="mws-textinput" placeholder="Post Name Goes Here." />
</div>
</div>
<div class="mws-form-row">
<label>Post Description:</label>
<div class="mws-form-item large">
<input type="text" name="post_description" id="post_description" class="mws-textinput" placeholder="Post Description Goes Here." />
</div>
</div>
<div class="mws-form-row">
<label>Post Keywords:</label>
<div class="mws-form-item large">
<input type="text" name="post_keywords" id="post_keywords" class="mws-textinput" placeholder="Post Keywords Goes Here, Separated By Commas!" />
</div>
</div>
<div class="mws-form-row">
<label>Post Content:</label>
<div class="mws-form-item large">
<textarea name="post_content" id="post_content" class="ckeditor" > </textarea>
</div>
</div>
<div class="mws-form-row">
<label>Post Tags:</label>
<div class="mws-form-item large">
<input type="text" name="post_tags" id="post_tags" class="mws-textinput" placeholder="Post Tags Goes Here, Separated By Commas!" />
</div>
</div>
<div class="mws-form-row">
<label>Edit Post Photo:</label>
<div class="mws-form-item large">
<input type="file" name="post_photo" id="post_photo" />
</div>
</div>
<div class="mws-form-row">
<label>Position:</label>
<div class="mws-form-item large">
<select name="position">
<?php
if (!$new_post) {
$post_set = get_posts_for_category($sel_post['category_id']);
$post_count = mysql_num_rows($post_set);
} else {
$post_set = get_posts_for_category($sel_category['id']);
$post_count = mysql_num_rows($post_set) + 1;
}
for ($count=1; $count <= $post_count; $count++) {
echo "<option value=\"{$count}\"";
if ($sel_post['position'] == $count) { echo " selected"; }
echo ">{$count}</option>";
}
?>
</select>
</div>
</div>
<div class="mws-form-row">
<label>Visible:</label>
<div class="mws-form-item large">
<input type="radio" name="visible" value="0"<?php
if ($sel_post['visible'] == 0) { echo " checked"; }
?> /> No
<input type="radio" name="visible" value="1"<?php
if ($sel_post['visible'] == 1) { echo " checked"; }
?> /> Yes
</div>
</div>
</form>
<div class="mws-button-row">
<input type="submit" name="submit" value="Add Post" class="mws-button green" />
<a class="mws-button red" href="index.php">Cancel</a>
</div>
</div>
</div>
</div>
</article>
<div class="clear"></div>
</div>
</article><!-- end of stats article -->
<div class="spacer"></div>
</section>
</body>
</html>
The way I would try to find the error:
make your errors visible:
<?php error_reporting(E_ALL); ?>
$target should be a full path.
Check your HTML form. Did you add the enctype attribute?
<form enctype="multipart/form-data" method="POST" action="script.php">
Is your Input correct?
<input type="file" name="post_photo"/>
What does the $_FILES array contents?
<?php echo print_r($_FILES); ?>
Edit
Please let us know the data these lines return:
<?php
error_reporting(E_ALL);
echo "<pre>";
print_r($_FILES);
echo "</pre>";
echo "<br/>target: " . $target;
if (!move_uploaded_file($_FILES['post_photo']['tmp_name'], $target)) {
echo "<br/>Upload failed.";
} else {
echo "<br/>Upload done."
}
?>
Edit 2 (Solution):
Your submit-button is outside the form-Tag. That's why. Fix it like this:
<form>
<input type="submit" name="submit" value="Add Post" class="mws-button green" />
</form>
Your $target should contain the root path
$target = $_SERVER['DOCUMENT_ROOT']"/upload/";
$target = $target . basename( $_FILES['post_photo']['name']);

Categories