After an image script

about lee

Addicted
Joined
Apr 8, 2010
Messages
937
Reaction score
0
FP$
6
Right so im after an image script, that would allow me to upload an image to my website (Not expandhost.com) my other site.

All im after is like a code, not a program. Which that would give me a code after wards.

Any ideas? Person to give me a code that i can get to work etc.. ill give you 800FP$.
 
Here you go:


Code:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 30000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
            move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "URL: " . "PLACE UPLOAD FOLDER PATH HERE" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Sorry, an error occurred. Your File was a format that we do not currently host.";
  }
?>
 
I pulled this straight from my old image hosting site. Just specify your upload folder url path where i marked it in the coding.
 
I did, it showed the code on web page: Sorry, an error occurred. Your File was a format that we do not currently host.

Doesnt even give me a box or anything. And yes i saved the file as php.
 
You said you only needed the part of the code that shows the link and stuff after the image was uploaded. you never said the whole form.

Code:
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

Change the form action file name to the php file you placed the other code in.
 
Ill give you a 1.000FP$ if you explain it to me and edit the page file:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head> 
<title>NetsLee - It's a personal thing</title>

                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
				<meta name="description" content="A personal site ran by one simple guy sharing hes crap with you." />
				<meta name="keywords" content="" /> 
				
			<link href="style.css" rel="Stylesheet" type="text/css" media="screen" />
			<link rel="stylesheet" type="text/css" href="tswtabs.css" />

</head>

<body>
<div class="wrap">

<div class="header">
	<img src="images/logo2.png" alt="some text" width="800" height="100"></img>
</div>

<div class="wrap">
		  <div class="menu">
    <ul>
      <li><a href="index.html" class="active"><span>Home</span></a></li>
      <li><a href="photo.html"><span>Photography</span></a></li>
      <li><a href="graphics.html"><span>Graphics</span></a></li>
	  <li><a href="request.html"><span>Request</span></a></li>
	  <li><a href="forum.html"><span>Forum</span></a></li>
      <li><a href="contact.html"><span>Contact</span></a></li>
 </ul>
  </div>
  <br />
		<div class="mainbox">
<div class="content">
PLACE THE CODE HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
</div>
<div class="bottom">
<p>&copy NetsLee - 2010</p>
</div>
</body> 
</html>
 
Here you go:
You WILL need to implement your site template in with this coding. You need to make sure that you look at the coding and put in the URLs where I have specified.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head> 
<title>NetsLee - It's a personal thing</title>

                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <meta name="description" content="A personal site ran by one simple guy sharing hes crap with you." />
            <meta name="keywords" content="" /> 
            
         <link href="style.css" rel="Stylesheet" type="text/css" media="screen" />
         <link rel="stylesheet" type="text/css" href="tswtabs.css" />

</head>

<body>
<div class="wrap">

<div class="header">
   <img src="images/logo2.png" alt="some text" width="800" height="100"></img>
</div>

<div class="wrap">
        <div class="menu">
    <ul>
      <li><a href="index.html" class="active"><span>Home</span></a></li>
      <li><a href="photo.html"><span>Photography</span></a></li>
      <li><a href="graphics.html"><span>Graphics</span></a></li>
     <li><a href="request.html"><span>Request</span></a></li>
     <li><a href="forum.html"><span>Forum</span></a></li>
      <li><a href="contact.html"><span>Contact</span></a></li>
</ul>
  </div>
  <br />
      <div class="mainbox">
<div class="content">
<br />
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</div>
<div class="bottom">
<p>&copy NetsLee - 2010</p>
</div>
</body> 
</html>

upload_file.php

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--


-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>NetsLee - It's a personal thing</title>
<meta name="keywords" content="free image hosting" />
<meta name="description" content="Users may upload images to our server to use on Myspace, Facebook, forums, blogs, etc." />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br />
<br />
<font color="red"><h3>Thankyou for uploading!</h3></font>
<br />
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 30000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
            move_uploaded_file($_FILES["file"]["tmp_name"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "URL: " . "URL TO YOUR FILE UPLOAD FOLDER" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Sorry, an error occurred. Your File was a format that we do not currently host.";
  }
?>
				
			</div>
			<div class="meta">
				<p class="byline"> </p>
				
			</div>
		</div>
	</div>
	<!-- end content -->
		<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

</div>
</body>
</html>
 
The page is not for everyone to use, but heres a quick preview of the code in place.

Clipboard03.jpg


And the page that appears when you have uploaded.

Clipboard01.jpg


Going to have a bash at like fancying the code up later.

But overall great code!
 
Back
Top Bottom