I can not create a folder in php - php

I'm developing an application that creates a folder by pressing a button if a certain condition is met. the issue is that the folder is created using the mkdir () and do not understand why. even the html page tells me that the folder was created, but this does not appear in the directory. I do not understand the error. the code is as follows:
<html>
<head>
<title>RHM</title>
<style type="text/css">
h1 { color: red; font-family: arial; font-size: 3em; font-weight: bolder; }
p { color: navy; font-family: Verdana; }
</style>
</head>
<body>
<h1 align="center">INGRESE CONTRASEÑA</h1>
<form action="#" method="post" >
<p align="center"> <input type="password" name="contras" style="width:200px;height:50px;background-color:yellow;color:blue;font-size:14pt;font-family: Comic Sans MS;text-align:center;padding-right:10px;"/></p>
<p align="center" ><input type="submit" value="Entrar" /></p>
<?php
$Contraseña=$_POST['contras'];
$estructura = "/home/bladimir/RHMbd";
if ($Contraseña==1) {
mkdir($estructura);
echo "<p>La carpeta fue creada</p>";
}
?>
</form>
</body>
</html>
Thank.

I'm guessing you don't have permission to create the directory.
Go to the folder /private/etc/apache2
Open httpd.conf
Find
User _www
Group _www
Change the username:
User <YOUR LOGIN USERNAME>
Restart apache.

<?php
if (isset($_POST['contras']))
{
$Contraseña = $_POST['contras'];
$estructura = "c:://home/bladimir/RHMbd";
$dir = dirname($estructura);
if (!is_dir($dir))
{
var_dump(mkdir($dir, 0777, true));
if ($Contraseña == '1')
{
echo 'fsdf';
mkdir($estructura);
echo "<p>La carpeta fue creada</p>";
}
}
}
?>

I solved it by giving the appropriate permissions to the user with the following command in console: chmod a + w bladimir. Thank for all.

Related

How to fix this PHP error that prints the code instead of the result?

It should print the error message, but instead it prints:
"data['clan_id'] != 0){echo "You already have a clan.";} ?>"
here is an image of the error: https://i.imgur.com/BtV7i9s.png
my code:
<html>
<style>
.createclanbutton {
background-color: green;
color: black;
padding: 3px;
border-radius: 9px;
}
</style>
<body>
<?php
if ($user->data['clan_id'] != 0)
{
echo "You already have a clan.";
}
?>
<br><br>
<form action="">
<h3>Create your own clan.<br><br>
Clan Name: <input type="text" name="ClanName" value="Clan Name"><br><br>
Description:<br> <textarea rows="6" cols="50">Brief description of your clan!
</textarea><br>
<button class="createclanbutton">Create your own clan!</button>
</form>
</body>
</html>
I am using phpbb and created a column called "clan_id" in my database which I set at "2" to try and echo the error message.
Looks like you have saved the file as .html or anything? :) You need to save this file as .php!

How do I access the php file in a local server from an another computer

I hosted my website on a localserver using xampp. So I was trying to access the website from another computer which was on the same network. I could access the index.html file that had to enter login details like the username and password but when I hit submit, I don't get to php page which should show the details of the user by retrieving it from the database. How am I suppose to access the php file too?
I was able to access the phpmyadmin page too from the other computer but can't access the php page as it says "the site can't be reached. localhost refused to connect"
My html code
<!DOCTYPE html>
<html>
<head>
<title>Login to Student's Database</title>
<style>
label {
font: normal 12px courier !important;
}
.sbm{
padding: 10px;
margin-left: 50px;
}
.whole{
background-image: url("images/bg-01.jpg");
background-attachment: fixed;
width: 1340px;
height: 640px;
background-repeat: repeat-x;
}
p {
font: bold 20px sans-serif;
padding: 20px;
}
</style>
</head>
<body>
<div class="whole">
<div align="center">
<form name="hun" method="post" action="http://localhost/exam/retrieve.php">
<p>Welcome To Student's Record</p>
<label for="user" > Username :</label>
<input type="text" name="username"><br><br>
<label for="pass"> Password :</label>
<input type="password" name="pass"> <br><br>
<div class="sbm"><input type="submit" name="submit"></div>
</form>
<div align="center">
</div>
</body>
</html>
My php code
<?php
$puser = $_POST['username'];
$ppass = $_POST['pass'];
$con = mysqli_connect('localhost','root','','student');
if(!$con)
{
die("Could not connect".mysql_error());
}
$pss=$ppass;
$usr=$puser;
$flag=0;
$que = "select * from rec";
$q = mysqli_query($con, $que);
if(!$q)
{
echo "Could not retrieve!";
}
else
{
while($ret = mysqli_fetch_array($q, MYSQLI_NUM))
{
if(($pss==$ret[1])&&($usr==$ret[0]))
{ $flag=1;
echo "Welcome to University<br>";
echo "Name = ";
echo $ret[2] . "<br>";
echo "Roll = ";
echo $ret[3]."<br>";
echo "Physics = ";
echo $ret[4]."<br>";
echo "Chemistry = ";
echo $ret[5]."<br>";
echo "Maths = ";
echo $ret[6];
}
}
}
if(!$flag)
{
echo "Wrong username or password";
}
?>

Display images from folder and delete images

I have this script from http://lampload.com/component/option,com_jdownloads/Itemid,382/cid,69/task,view.download/
(I am not using a database) I can upload images fine, I can view files, but I want to delete them.
When I press the delete button, nothing happens
http://www.jayg.co.uk/gallery6/upload_gallery.php
<?php
$dir = dirname(__FILENAME__)."/images/gallery" ;
$files1 = scandir($dir);
foreach($files1 as $file){
if(strlen($file) >=3){
$foil = strstr($file, 'jpg'); // As of PHP 5.3.0
$foil = $file;
$pos = strpos($file, 'css');
if ($foil==true){
echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />';
echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host
//echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>";
}
}
}?>
<input type="submit" name="mysubmit2" value="Delete">
</form>
any ideas?
Waw!, the way you are going about it is wrong. For simplicity why don't you implement database
in the codings. Anyway based on your request, I have developed this code along with css file. it has been tested and its working now. Please rate my response and give me a shout if you need futher assistance. .... Sectona
index.php
<?php
extract($_REQUEST);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style>
#box{ width:200px; height:auto; border:solid #999 10px; padding:10px; margin:0 auto; margin-top:100px; background-color:#FFF;-webkit-box-shadow: 0 1px 2px #666;box-shadow: 0 1px 2px #666; color:#66F;}
.link{padding:5px; text-decoration:none; background-color:#333; color:#FFF}
</style>
</head>
<body>
<div id="box">
<img src="images/3.jpg" />
<p></p>
Delete
</div>
</body>
</html>
delete.php
<?php
extract($_REQUEST);
unlink("images/3.jpg");
// Redirect to a page that prints image deleted successfully
header("Location:success_delete.php");
?>

Image display's on localhost but not on server

I have exactly same code on my localhost,and it display's everything perfectly,so i copied file to server that im hosting on (000webhost.com) and now it didnt display image,when i open inspect element,it show's that image is there,and image is also uploaded to save folder with that file.Image is at the bottom of the file.
<html>
<head>
<style>
<!--
body{
background-color:black;
}
#form{
position:absolute;
top:180px;
left:37%;
border-radius:20px;
padding:10px;
padding-bottom:50px;
background-color:white;
z-index:1;
}
#login_b{
position:relative;
left:38px;
top:30px;
width:150px;
color:white;
background-color:#777777;
}
#header1 {
position:absolute;
top:115px;
left:39%;
text-shadow:10px 5px 5px #888888;
color:white;
z-index:2;
}
#header2 {
position:absolute;
left:20%;
top:-50px;
font-size:100px;
color: yellow;
}
#image1 {
height:77%;
position:relative;
top:280px;
}
-->
</style>
</head>
</body>
<?php
include 'scripts/config.php';
checkIfLoggedIn();
//error_reporting(0);
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
$q = $dbc->prepare("SELECT * FROM users WHERE username = '$username' AND password = '$password'");
$query = $q->execute(array(
$username,
$password
));
$count = $q->fetchColumn();
if($count){
$_SESSION['Username'] = $username;
header('Location: main.php');
return;
} else {
echo '<font color="white">You have entered and incorrect login!</font>';
}
}
?>
<h1 id="header2">ARAM STATS!</h1>
<h1 id="header1">Admin login</h1>
<div id="form">
<form action="" method="POST">
Username:
<input type="text" name="username">
<br>
Password:
<input type="password" name="password">
<br>
<input type="submit" name="submit" value="Login" id="login_b">
</form>
</div>
<img src="/lolimage.jpg" id="image1">
</body>
</html>
Do i have to change something on the server? When i highlight it,it becomes blue: http://piclair.com/album but it doenst display it.Doesnt make any sense.
I don't have enough reputation to comment.
Where is located the image file ? If it's in the same directory of your page you should try
<img src="lolimage.jpg" id="image1">
You mention a "save folder", is it where are located your images ? If so you should add the directory to the path.
<img src="save/lolimage.jpg" id="image1">
Just add your sites base url before your image name.
This may help you
for example,
<img src="<your_sites_base_url>/<image_name>" />
There can be lot of reasons -
try to open the image directly by giving folder path in browser like : xyz.com/yourfolder/imagefolder/images.jpg . if you are able to see it then check the src you have given for image. It should be relative path. use src = "../path/image.jpg" based on location of you html/php file and image. If image is in same folder of the file that no need to add '/'

PHP code being commented out

I'm using CentOS 6.4 with apache installed. I have a single php file called cmsSearch.php. At the top of the file I have PHP that executes fine (queries a Sphinx Search index). But, any php I try to run in the HTML that is below (trying to run a foreach and populate a table with the results of the Sphinx Search) just gets commented out when I view the page in the console (Chrome). Here is the whole cmsSearch.php file:
<?php
require("sphinxapi.php");
if($_POST['keyword'])
{
$keyword = $_POST['keyword'];
$client = new SphinxClient();
$client->SetMatchMode(SPH_MATCH_ANY);
$result = $client->Query($keyword, "staffDirectoryMember");
if(!$result)
{
print "ERROR: " . $client->GetLastError();
}
else
{
var_dump($result["matches"]);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sphinx Test</title>
<style>
.container
{
border: solid 1px black;
height: 350px;
width: 700px;
margin: auto;
padding: 5px;
}
.output
{
margin-top:20px;
border: solid 1px red;
height: 200px;
}
</style>
</head>
<body>
<?echo "TEST"; ?>
<div class="container">
<div>
<form method="post" action="cmsSearch.php">
<input type="text" name="keyword">
<input type="submit" value="Search">
</form>
<div class="output">
<? echo "test2"; ?>
<table>
<thead>
<tr>
<th>ID</th>
<th>Weight</th>
<th>ClientId</th>
<th>DomainId</th>
<th>ContentTypeId</th>
</tr>
</thead>
<tbody>
<?
echo "Above for loop";
foreach($result["matches"] as $match)
{
echo "Print from for loop:";
var_dump($match);
?>
<!-- <tr>
<td><?=$match[id]?></td>
<td><?=$match[weight]?></td>
<td><?=$match[attrs][clientid]?></td>
<td><?=$match[attrs][domainid]?></td>
<td><?=$match[attrs][contenttypeid]?></td>
</tr> -->
<?}
echo "After for loop";
?>
</tbody>
</table>
</div>
</div>
</div>
Not sure why the php executes at the top fine (i can echo out and the var dump works), but then any php put in the HTML just shows as comments and doesn't do anything. Anyone have an idea?
Your PHP contained inside the HTML is using short tags which can be turned off in your php.ini file. Take a look at this directive and make sure it is set to true if you want to use them:
short_open_tag true
http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
Try using <?php to start your PHP blocks, not <?... It's the difference between the blocks of code.

Categories