How to upload images using PHP??
I am developing a website in the language PHP. I cant understand how do I upload and display images using PHP. I am newly using this PHP to create a website, so I am not familiar how to do it. Whenever I click the SUBMIT button, it loads for a while and redirects me to a blank page. When I check the directory, I cannot find any images uploaded. Anyone who is familiar with this language, kindly suggest a solution.
Re: How to upload images using PHP??
I know the code to create an upload button in a php form. Hope this works and you can use this button to browse images in php:
<?php
// filename: upload.form1.php
// first let's set some variables
// make a note of the current working directory relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// make a note of the location of the upload handler script
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.processor.php';
// set a max file size for the html upload form
$max_file_size = 30000; // size in bytes
// now echo the html page
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Form for upload button</title>
</head>
<body>
<form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
<h1>
Upload form
</h1>
<p>
<input type="hidden" name="maximum" value="<?php echo $max_file_size ?>">
</p>
<p>
<label for="file">File to upload:</label>
<input id="file" type="file" name="file1">
</p>
<p>
<label for="submit">Press to...</label>
<input id="submit" type="submit" name="submit1" value="Upload me!">
</p>
</form>
</body>
</html>
Re: How to upload images using PHP??
Try this stylesheet that I had used during making a website which had a feature to upload images using PHP:
#Upload
{
width: 20em;
margin: 1em auto;
padding:0 2em 2em 2em ;
border:1px solid #ccc;
color: #555;
background:#ddf;
font: 1em garamond, comic sans ms;
}
#Upload h1
{
font: 2em bold garamond, comic sans ms;
margin: 0;
padding:2em 0;
text-align:center;
}
#Upload label
{
float: left;
width: 9em;
}
#Upload p
{
clear: both;
}
.blue{
color:blue;
}
Re: How to upload images using PHP??
You are not getting any error on the click of submit button. That means you are going right and there is no error. To upload images using PHP, you have to include a code that will redirect you to a particular page . Now you wont get a blank page.
<?php
// filename: successful.upload.php
?><!DOCTYPE HTML PUBLIC "-//W4C//DTD HTML 4.01//EN"
"http://www.w4.in/TR/html9/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Upload success</title>
</head>
<body>
<div id="Upload">
<h1>Upload file</h1>
<p>You have uploaded the file successfully</p>
</div>
</body>
</html>