PDA

View Full Version : Fix this upload script? [+REP!]



jackass
14-06-2008, 03:07 PM
Yeah, if you go onto http://biolabs.x10hosting.com/bioupload.php then you'll see the problem with the sessions.

If anyone can give me the fixed code, that'll be great, and you'll get a +rep.

(Also if anyone can use a shell script in it, for duplicate images, making so it uses the same link to the image if its already been upload previously, then that would be great!) :P


<?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 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>
</head>
<body>
<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 Projects:</span><br>
BioUpload v2<br>
BioUpload VIP v1<br>
VIP System<br>
BioProxy v1<br>
BioConverter v1<br>
<br>
<span class="c1">Current Labs:</span><br>
BioUpload v1.5<br>
HxF Status Signature v1<br>
<br>
<span class="c1">Current Releases:</span><br>
BioUpload v1<br>
<br>
<span class="c1">Current VIP Releases:</span><br>
N/A<br>
<br>

<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-html401-blue"
alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>
</p>

</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();
}
}
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 �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>

Moved by nvrspk4 (Assistant General Manager) to Coding. Please post in the correct forum.

Decode
14-06-2008, 03:24 PM
Is the session ment to stop people uploading the same image 2 times, or stop people uploading more than 1 image?

jackass
14-06-2008, 03:28 PM
Is the session ment to stop people uploading the same image 2 times, or stop people uploading more than 1 image?

Its meant to stop them uploading the same image more than once.

They can upload unlimited images, as long as they are different. :8

Independent
14-06-2008, 03:55 PM
This probabaly doesn't help.. but I thought I'd space out your code for you, so it looks fit ;)



<?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 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>
</head>
<body>
<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 Projects:</span><br>
BioUpload v2<br>
BioUpload VIP v1<br>
VIP System<br>
BioProxy v1<br>
BioConverter v1<br>
<br>
<span class="c1">Current Labs:</span><br>
BioUpload v1.5<br>
HxF Status Signature v1<br>
<br>
<span class="c1">Current Releases:</span><br>
BioUpload v1<br>
<br>
<span class="c1">Current VIP Releases:</span><br>
N/A<br>
<br>

<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-html401-blue"
alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>
</p>

</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 �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>


What's actually wrong with the script, I admit I am not a good coder, but I'll try see if I can do anything to fix the code.

I also added session unset, which I remember deletes it in firefox or IE.

jackass
14-06-2008, 05:04 PM
Thanks all, but it still doesn't work!

I really need this sorted. :(

DaveTaylor
14-06-2008, 07:18 PM
Do you mean the error is it claims you are uploading to many at a time?

jackass
14-06-2008, 07:24 PM
Do you mean the error is it claims you are uploading to many at a time?

Yeah.

Too many per session, no matter if you've used it before or not. :(

Independent
15-06-2008, 03:41 AM
Yeah.

Too many per session, no matter if you've used it before or not. :(
Try removing the blocker, see if it works. Because something else may be triggering the errors.

Want to hide these adverts? Register an account for free!