Upload script not working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Biolabs
Forum Newbie
Posts: 1
Joined: Sun Jun 15, 2008 7:48 am

Upload script not working?

Post by Biolabs »

http://biolabs.x10hosting.com/bioupload.php

My upload script, no matter how many times you upload something, even if you have never used it, it comes up with the same message 'too many uploads per session'. Below are the codes...

This is the upload form code (the one shown on that link up above):

Code: Select all

<?php session_start();
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 
  <meta name="generator" content="HTML Tidy for Linux (vers 1 September 2005), see http://www.w3.org">
 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Biolabs v1</title>
 
 
  <link href="style.css" rel="stylesheet" type="text/css">
 
  <style type="text/css">
/*<![CDATA[*/
li.c2 {list-style: none}
span.c1 {font-weight: bold;}
/*]]>*/
  </style>
  <style type="text/css">
<!--
.style2 {font-size: 36px}
-->
  </style>
</head>
 
 
 
<body style="background-color: rgb(0, 0, 0);">
 
<div id="holder">
<div id="header">
<div id="logo2"><img src="images/newlogo.bmp" alt="logo"></div>
 
<br>
 
<div id="menu">
<ul>
 
  <li><a href="index.html">Home</a></li>
 
  <li><a href="scripts.html">Scripts</a></li>
 
  <li><a href="vip.html">VIP</a></li>
 
  <li><a href="bioupload.php">BioUpload</a></li>
 
  <li><a href="about.html">About</a></li>
 
</ul>
 
</div>
 
</div>
 
<div id="main">
<div id="sidebar"><span class="c1">Current
BioTools:<br>
 
<span style="font-weight: normal;">BioUpload - v1.12</span><br style="font-weight: normal;">
 
<span style="font-weight: normal;">BioConverter - Alpha
v0.08</span><br style="font-weight: normal;">
 
<span style="font-weight: normal;">BioProxy - Alpha v0.05</span><br>
 
<br>
 
Current Scripts:<br>
 
<span style="font-weight: normal;">HxF Status Signature -
Beta v0.7</span><br style="font-weight: normal;">
 
<span style="font-weight: normal;">Ingenerator - Alpha
v0.05</span><br>
 
<br>
 
Site version - v1.28<br>
 
</span>
<br>
 
<a href="http://validator.w3.org/check?uri=referer"><img style="border: 0pt none ; width: 88px; height: 31px;" src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a><a href="http://jigsaw.w3.org/css-validator/"> <img style="border: 0pt none ; width: 88px; height: 31px;" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!"></a>
<br>
 
<br>
 
<a href="http://www.x10hosting.com/?rid=91209"> <img style="border: 0pt none ;" src="images/x10hosting.gif" alt="x10hosting">
</a> </div>
 
<div id="text">
<div align="center"><br>
 
<br>
 
<span class="style2"><font color="#000000">Biolabs
Image Uploader v1.12</font></span><br>
 
<br>
 
</div>
 
<center>
<p><font color="#000000">Choose the image you want
to upload, The image must be less than 1MB in size.</font><br>
 
<font color="#000000">There is no limit to the ammount of
images that you upload!</font><br>
 
<font color="#000000">Inappropriate images are NOT allowed!</font></p>
 
<form action="bioupload2.php" enctype="multipart/form-data" method="post"> <input name="user_file" size="50" type="file"> <br>
 
  <br>
 
  <input name="submit" value="Upload Now" type="submit"></form>
 
</center>
 
</div>
 
</div>
 
<div id="footer">
<div id="left_footer"><strong><strong>Copyright
&copy;2008 Biolabs.co.uk</strong></strong></div>
 
<div id="right_footer"><strong><strong>Site
created by Jack Moore</strong></strong></div>
 
</div>
 
</div>
 
</body>
</html>
 
And here is the code for the upload script (the one which uplaods the image given, and gives the link for it):

Code: Select all

<?php session_start();
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 
  <meta name="generator" content="HTML Tidy for Linux (vers 1 September 2005), see http://www.w3.org">
 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Biolabs v1</title>
 
 
  <link href="style.css" rel="stylesheet" type="text/css">
 
  <style type="text/css">
/*<![CDATA[*/
li.c2 {list-style: none}
span.c1 {font-weight: bold;}
/*]]>*/
  </style>
  <style type="text/css">
<!--
.style2 {font-size: 36px}
-->
  </style>
</head>
 
 
 
<body style="background-color: rgb(0, 0, 0);">
 
<div id="holder">
<div id="header">
<div id="logo2"><img src="images/newlogo.bmp" alt="logo"></div>
 
<br>
 
<div id="menu">
<ul>
 
  <li><a href="index.html">Home</a></li>
 
  <li><a href="scripts.html">Scripts</a></li>
 
  <li><a href="vip.html">VIP</a></li>
 
  <li><a href="bioupload.php">BioUpload</a></li>
 
  <li><a href="about.html">About</a></li>
 
</ul>
 
</div>
 
</div>
 
<div id="main">
<div id="sidebar"><span class="c1">Current
BioTools:<br>
 
<span style="font-weight: normal;">BioUpload - v1.12</span><br style="font-weight: normal;">
 
<span style="font-weight: normal;">BioConverter - Alpha
v0.08</span><br style="font-weight: normal;">
 
<span style="font-weight: normal;">BioProxy - Alpha v0.05</span><br>
 
<br>
 
Current Scripts:<br>
 
<span style="font-weight: normal;">HxF Status Signature -
Beta v0.7</span><br style="font-weight: normal;">
 
<span style="font-weight: normal;">Ingenerator - Alpha
v0.05</span><br>
 
<br>
 
Site version - v1.28<br>
 
</span>
<br>
 
<a href="http://validator.w3.org/check?uri=referer"><img style="border: 0pt none ; width: 88px; height: 31px;" src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a><a href="http://jigsaw.w3.org/css-validator/"> <img style="border: 0pt none ; width: 88px; height: 31px;" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!"></a>
<br>
 
<br>
 
<a href="http://www.x10hosting.com/?rid=91209"> <img style="border: 0pt none ;" src="images/x10hosting.gif" alt="x10hosting">
</a> </div>
 
<div id="text">
<?php
$n = $_FILES['user_file']['name'];
$type = $_FILES['user_file']['type'];
$size = $_FILES['user_file']['size'];
$time = time();
$n = $time;
$path = "uploads/". $n;
 
$uploaded = $_SESSION['firsttimeupload'];
if ($uploaded == "ok")
{
       if ($size <1048576 && ereg("image", $type  ))
          {
   move_uploaded_file($_FILES['user_file']['tmp_name'],
   $path);
   
   $root = "http://biolabs.x10hosting.com/uploads/";
   $path2 = $root . $n;
   echo "<center>";
   echo "<h3><span style='color: #000;'><center><b>Your Image Link Is: </h3><a href=$path2>$path2</a></b><center></span>"; 
   echo "<br>";
   echo "<img src=$path2 border='5'></img>";
   echo "<center>";
   
   
   $fp=fopen("links.text", "at");
   fwrite($fp, $path2."\n");
   fclose($fp);
   session_destroy();
   session_unset();
          }    
}   
else
{
echo("<span style='color: #000;'><center><b>You can't upload the same image too many times per session!<br>Go back and choose another one!</b><center></span>");
}  
    
////////////
     if ($size>1048576)
       {
echo("<span style='color: #000;'><center><b>ERROR<br>The image size is too big!</b><center></span>");
       }
     if (!ereg("image", $type) )
      {
echo("<span style='color: #000;'><center><b>ERROR<br>The file is not image!</b><center></span>");
       }
echo "";
?>
</div>
 
</div>
 
<div id="footer">
<div id="left_footer"><strong><strong>Copyright &#65533;2008 Biolabs.co.uk</strong></strong></div>
 
<div id="right_footer"><strong><strong>Site created by Jack Moore</strong></strong></div>
 
</div>
 
</div>
 
</body>
</html> 
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Upload script not working?

Post by califdon »

Your upload script branches to that error message if the variable $uploaded does not equal "OK". The variable $uploaded gets it value from a session variable $_SESSION['firsttimeupload']. But you don't seem to have ever assigned any value to the session variable (or indeed, any session variable) in either script. Looks like there is an entire section of code missing from your scripts.
Post Reply