-1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>Validate Image</TITLE>
  <META NAME="Author" CONTENT="Bit Repository">

  <META NAME="Keywords" CONTENT="validate, extensions, file, javascript">
  <META NAME="Description" CONTENT="A JavaScript Extension Validator for Images">

<SCRIPT LANGUAGE="JavaScript">

<!--
function validate()
{
var extensions = new Array("jpg","jpeg","gif","png","bmp");


var image_file = document.form.image_file.value;

var image_length = document.form.image_file.value.length;

var pos = image_file.lastIndexOf('.') + 1;

var ext = image_file.substring(pos, image_length);

var final_ext = ext.toLowerCase();

for (i = 0; i < extensions.length; i++)
{
    if(extensions[i] == final_ext)
    {
    return true;
    }
}

alert(" Upload an image file with one of the following extensions: "+ extensions.join(', ') +".");
return false;
}
 //-->

 </SCRIPT>

 </HEAD>
 <?php 
if(isset($_POST['submit']))
{
$current_image=$_FILES['image_file']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg") && ($extension != "gif") && ($extension != "png") && ($extension != "bmp")) 
{
die('Unknown extension');
}
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination="uploads/".$new_image;
$action = copy($_FILES['image_file']['tmp_name'], $destination);
if (!$action)

{
die('File copy failed');
}
else
{
echo "File copy successful";
echo"<br>";
echo "<a href='upload_image.php'>Back</a>";
}
 
}
else
{
?>

<BODY>

<center>

<form name="form" action="" enctype="multipart/form-data" method="post" onSubmit="return validate();">

<h2>Upload an image</h2>

<br />

	Upload an image: <INPUT type="file" name="image_file"> <input type="submit" name="submit" value="Submit">

</form>

</center>

</BODY>
<?php
}
?>
</HTML>
2
Contributors
10
Replies
17
Views
6 Years
Discussion Span
Last Post by vijiglad
0

What is the question? I hope that you just forgot to mention or something happened during editing the post.

1

And I want a PHP script that will add to my bank account (in a legitimate way) one million dollars. I can’t speak for others, but I believe that forums (fine ones like daniweb) are for sharing knowledge. What are your needs? Do you need the image to appear once and then lost? Do you want to save it somewhere? I see that you validate if it is image by extension … the problem is that your server don’t support mime_content_type function? . I also see that you save the “image” in a destination… so you set where the image will be and with what name… What exactly is the problem of using that image in html?

Votes + Comments
I'll take one million, too. You get half of it for your patience.
0

i want php script to view the image stored in folder "uploads"..

0

<img src="<?php echo $destination;?>" />

Edited by jkon: closing tags missed

0

I assume that you have no (or lower then elementary) knowledge or experience in web development, this is not bad as long it innovate you to learn things. You provided a script with lots of problems as I pointed to my last post (how are you sure it is image and not Trojan? only by extension?). You say that your problem is that you want to view the image uploaded , well you save it somewhere (in $destination in your script) so I believe that you know the path to it.

If you don’t understand even the script that you provided just point what puzzle you to help.

If you know the path and that path is under public html just use an html img tag to output it and for destination the destination that your script knows. Please if any of this isn’t clear enough don’t hesitate to ask specific questions just do not hit finger on desk saying … “script please… ”

0

i know img tag.. i want to display all the images in that folder.. for example if i click "next" next image should be displayed.. please help

0

What is the reason to guess what you trying to do? Could you say that in first place? Now you say “if i click "next" next image should be displayed” . If you click next where? You saved your “images” or Trojans with names depending on timestamp that uploaded. Do you want to have a page that displays all that images? Do you want to have a page that display only one image and with next receiving the next one by name order? And frankly explain me if you can why is it so difficult for you to expose your questions …

0

i want to display only one image and by clicking "next" next image should display..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.