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 '/'
Related
I built a file upload form in PHP, IT WORKS fine when it comes to images, but it will not upload an audio file.
I can upload all (most) other files, but can't upload mp4/mp3/wav
It registers as no file for some reason (it won't even echo out the file information like it does with images and other files) My code works just well for other types of files.
I have searched for a solution before posting this.
The code is below and you may try it.
Here is the code:
<?php
if (isset($_FILES['UploadFileField'])){
$UploadName = $_FILES['UploadFileField']['name'];
$UploadTmp = $_FILES['UploadFileField']['tmp_name'];
$UploadType = $_FILES['UploadFileField']['type'];
$FileSize = $_FILES['UploadFileField']['size'];
$UploadName = preg_replace("#[^a-z0-9.]#","",$UploadName);
echo $UploadName."</br>";
echo $UploadTmp."</br>";
echo $UploadType."</br>";
echo $FileSize."</br>";
if ($FileSize > 100000){
die("Error - File Too Big");
}
if(!$UploadTmp){
die("No File Selected, Please Upload Again");
}else{
move_uploaded_file($UploadTmp,"Uploads/$UploadName");
}
}
?>
<!Doctype HTML>
<html>
<head>
<style>
.fileuploadholder{
width:400px;
height:200px;
margin: 60px auto 0px auto;
background-color:#FFF;
border: 1px solid #CCC;
}
</style>
</head>
<body>
<div class="fileuploadholder">
<label for="UploadFileField"></label>
<form action="FileUpload.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
<input type="file" name="UploadFileField" id="UploadFileField"/>
<input type="submit" name="UploadButton" value="Upload"/>
</form>
</div>
</body>
</html>
I commented out PHP comments on my script. but they still appear on my webpage in HTML. Do you have any idea how do I fix this?
kind regards,
/*if (isset($_POST['submitted'])) {
//require_once is similar to 'include' but ensures the code is not copied multiple times
require_once('LoginFunctions.php');*/
this text appear on my webpage:
my whole script:
Here is my whole script so you can identify where the mistake is.
<link rel="stylesheet" href="style.css">
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include 'Header.php';
?>
<style>
body
{
background-color:#FFFFC2;
alignment-adjust: central;
float: none;
background-image: url("images_1/sea-sanctuaries-siteimage01.jpg");
alignment-baseline: central;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height:100%;
}
#div_1 {
width: 40%;
hight: 80%;
background-color: bisque;
border: 5px;
border-radius: 25px;
}
#div_2 {
font-family: sans-serif;
padding-bottom: 10px;
padding-right: 50px;
margin-top: 5px;
margin-right: 50px;
}
</style>
<body>
<div id="container">
<br>
<?php
/*
if($_DEBUG)
{
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
}
$page_title = 'Login';/* */
//in this page we do things slightly differently - the code for validation and displaying messages is done
//before we display the form
echo '<div id = "div_1><h1>Login</h1>';
//display the form
echo '<div id="div_2"><div id="div_2">
<form action="index.php" method="post">
<label>UserName<br>
<span class="small">enter your username</span>
</label>
<input type="text" name="UserName" value=""/>
<label><br>Password<br>
<span class="small">enter your password</span>
</label>
<input type="password" name="Password" />
<button type="submit" name="submit" value="Login" />Log in</button>
<input type ="hidden" name="submitted" value="TRUE">
</form>
</div>
</div>';
/* if (isset($_POST['submitted'])) {
//require_once is similar to 'include' but ensures the code is not copied multiple times
require_once('LoginFunctions.php');
//list() is a way of assigning multiple values at the same time
//checkLogin() function returns an array so list here assigns the values in the array to $check and $data
list($check, $data) = checkLogin($_POST['UserName'], $_POST['Password']);
if ($check) {
setcookie('FName', $data['FName'], time()+ 900 ) ; //cookie expires after 15 mins
setcookie('LName', $data['LName'], time() + 900 ) ;
//
//use session variables instead of cookies
//these variables should now be available to all pages in the application as long as the users session exists
$_SESSION['FName'] = $data['FName'];
$_SESSION['LName'] = $data['LName'];
$_SESSION['UserName'] = $data['UserName'];
//to enable $_SESSION array to be populated we always need to call start_session() - this is done in header.php
//print_r is will print out the contents of an array
//print_r($_SESSION);
//
//Redirect to another page
$url = absolute_url('Index.php'); //function defined in Loginfunctions.php to give absolute path for required page
$logged = true;
//this version of the header function is used to redirect to another page
header("Location: $url");//since we have entered correct login details we are now being directed to the home page
exit();
} else {
$errors = $data;
}
}
//create a sopace between the button and the error messages
echo'<div class="spacer"></div>';
if (!empty($errors)) {
echo '<br/> <p class="error">The following errors occurred: <br />';
//foreach is a simplified version of the 'for' loop
foreach ($errors as $err) {
echo "$err <br />";
}
echo '</p>';
}
//this is the end of the <div> that contains the form
echo '</div>';
/* */
?>
</div>
</body>
<?php
include 'Footer.php';
?>
comment them inside PHP code sections
<?php /* code here will not display in html */ ?>
<!-- code here will be visible (in view source) -->
If your php interpreter is not running there's no way to hide php code.
You forgot one " in the line
echo '<div id = "div_1><h1>Login</h1>';
which apparently causes it, somehow, to continue echoing what comes after.
Solution: add the missing " after the div_1
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.
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");
?>
i am new to php to developing simple content management system i have a field like menu, position, visible, img_des, content, information_id .. it almost all working correctly now i need to insert image field to that . i have a separate file for forms and new page creation
now the following code
if (isset($_POST['submit'])) {
$errors = array();
// clean up data before putting in the database
$information_id = mysql_prep($_GET['info']);
$menu = trim(mysql_prep($_POST['menu'])); // cut out whitespace for menu
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
$image = mysql_prep($_POST['image']);
$img_des = mysql_prep($_POST['img_des']);
$content = mysql_prep($_POST['content']);
if(empty($errors)){
$query = "INSERT INTO pages (
menu, position, visible, img_des, content, information_id
) VALUES (
'{$menu}', {$position}, {$visible},'{$img_des}', '{$content}', {$information_id}
)";
if ($result = mysql_query($query, $connection)) {
$message = "The new page was created successfully";
$new_page_id = mysql_insert_id();
redirect_to("content.php?page={$new_page_id}");
} else {
$message = "The page failed to create";
}
?>
before img_des i want to insert image. what type i have i have to use and what code i have to put to insert and retrieve image.
You shouldn't be storing images in the database. Save the image on the server and save a link to the files location in the database.
see this question for more information: What should I use to save a image in database
try this code.
<?php
$images_arr = array();
//This is the directory where images will be saved
$target_dir = "uploads/";
$target = $target_dir.$_FILES['photo']['name'];
//$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
$bands=$_POST['otherBands'];
// Connects to your Database
mysql_connect("Localhost", "remote", "remote123") or die(mysql_error()) ;
mysql_select_db("test") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO dbProfiles (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)){
//Tells you if its all ok
echo "The file ". $target_dir.$_FILES['photo']['name']. " has been uploaded, and your information has been added to the directory";
$images_arr[] = $target;
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="http://www.thesoftwareguy.in/favicon.ico" type="image/x-icon" />
<!--iOS/android/handheld specific -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Upload multiple images create thumbnails and save path to database with php and mysql">
<meta name="keywords" content="php, mysql, thumbnail,upload image, check mime type">
<meta name="author" content="Shahrukh Khan">
<title>Upload multiple images create thumbnails and save path to database with php and mysql </title>
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
.files{height: 30px; margin: 10px 10px 0 0;width: 250px; }
.add{ font-size: 14px; color: #EB028F; border: none; }
.rem a{ font-size: 14px; color: #f00; border: none; }
.submit{width: 110px; height: 30px; background: #6D37B0; color: #fff;text-align: center;}
</style>
<script src="jquery-1.9.0.min.js"></script>
<script>
$(document).ready(function() {
$(".add").click(function() {
$('<div><input class="files" name="user_files[]" type="file" ><span class="rem" ><a href="javascript:void(0);" >Remove</span></div>').appendTo(".contents");
});
$('.contents').on('click', '.rem', function() {
$(this).parent("div").remove();
});
});
</script>
</head>
<body>
<form name="f1" action="index.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="image_form_submit" value="1"/>
<div id="container">
<div id="body">
<div class="mainTitle" >Upload multiple images create thumbnails and save path to database with php and mysql</div>
<div class="height20"></div>
<article>
<div class="height20"></div>
<div style="width: 380px; margin: 0 auto;">
<h3 style="text-align: center;">Image will be resized to 100px X 100px </h3>
<p>Please Enter the Band Members Name.</p>
<p> Band Member or Affiliates Name:</p>
<input type="text" name="nameMember"/>
<p>
Please Enter the Band Members Position. Example:Drums.
</p>
<p>
Band Position:
</p>
<input type="text" name="bandMember"/>
<p>
Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.
</p>
<p>
Photo:
</p>
<input type="hidden" name="size" value="350000">
<input type="file" name="photo">
<p>
Please Enter any other information about the band member here.
</p>
<p>
Other Member Information:
</p>
<textarea rows="10" cols="35" name="aboutMember">
</textarea>
<p>
Please Enter any other Bands the Member has been in.
</p>
<p>
Other Bands:
</p>
<input type="text" name="otherBands" size=30 />
<br/>
<br/>
<input TYPE="submit" name="upload" title="Add data to the Database" value="Add Member"/>
</div>
<table class="bordered">
<?php
// fetch all records
$sql = "SELECT * FROM dbProfiles WHERE 1 "; ?>
<?php
$sql="SELECT * FROM dbProfiles";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><p><?php echo $row['nameMember'] ?>"</p></td>
<td><img src="uploads/<?php echo $row['photo'] ?>" width="200px" height="200px;"/><p><?php echo $row['nameMember'] ?>"</p></td>
</tr>
<?php
}
?>
</table>
</article>
</div>
</div>
<div class="height10"></div>
</form>
</body>
</html>
<?php
function errorMessage($str) {
return '<div style="width:50%; margin:0 auto; border:2px solid #F00;padding:2px; color:#000; margin-top:10px; text-align:center;">' . $str . '</div>';
}
function successMessage($str) {
return '<div style="width:50%; margin:0 auto; border:2px solid #06C;padding:2px; color:#000; margin-top:10px; text-align:center;">' . $str . '</div>';
}
?>