Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

File Upload Problem

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

Barrucadu

Established Member
Impact
64
Heres the code:

PHP:
<?php
		$startHTML="<body bgcolor=\"#CCCCCC\">
		<title>Uploading</title>
<div align=\"center\">
  <table width=\"200\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" bgcolor=\"#FFFFFF\">
    <tr>
      <td><p><span class=\"style1 style2\"><img src=\"Images/Banner.gif\" width=\"600\" height=\"200\" border=\"0\" usemap=\"#Map\"></span>
            <map name=\"Map\">
              <area shape=\"rect\" coords=\"231,47,287,92\" href=\"Search.php\">
              <area shape=\"rect\" coords=\"297,49,350,92\" href=\"home.php\">
              <area shape=\"rect\" coords=\"357,48,414,93\" href=\"terms.php\">
              <area shape=\"rect\" coords=\"423,48,485,93\" href=\"contact.php\">
              <area shape=\"rect\" coords=\"491,47,571,90\" href=\"http://1.myfreebulletinboard.com/index.php?http://1.myfreebulletinboard.com/index.php?mforum=picminder\">
          </map>
      </p>";
		echo $startHTML;

 // Where the file is going to be placed temporarly
$target_path = "/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$_FILES['uploadedfile']['tmp_name']; // temp file

$target_path = "./uploads/";
$oldfile =  basename($_FILES['uploadedfile']['name']);

// checking the extention
$ext = strrchr($_FILES['uploadedfile']['name'], '.');

if((!$ext==".gif")&&(!$ext==".zip")&&(!$ext==".jpg")&&(!$ext==".jpx")&&(!$ext==".jpe")&&(!$ext==".jpeg")&&(!$ext==".png")&&(!$ext==".bmp")&&(!$ext==".wmv")&&(!$ext==".avi")&&(!$ext==".mpg")&&(!$ext==".mov")&&(!$ext==".asf")&&(!$ext==".asx")&&(!$ext==".swf")&&(!$ext==".3g2")&&(!$ext==".mp4")&&(!$ext==".mp3")&&(!$ext==".wav")&&(!$ext==".mid")&&(!$ext==".gz")&&(!$ext==".arc")&&(!$ext==".arg")&&(!$ext==".czip")&&($ext==".doc")&&(!$ext==".xls")&&(!$ext==".mdb")&&(!$ext==".ppt")&&(!$ext==".txt")&&(!$ext==".rtf")){

   echo "Dissallowed File Extension!";
   echo "<p>Allowed extensions are .zip, .gif, .bmp, .jpg, .png, .wmv, .avi, .mpg, .mov, .asf, .asx, .swf, .3g2, .mp4, .mp3, .wav and .mid</p>";
   die( "<p><a href=\"Home.php\">Try Again</a></p>");

}else if(($ext==".wmv") or ($ext==".avi") or ($ext==".mpg") or ($ext==".mov") or ($ext==".asf") or ($ext==".asx") or ($ext==".swf") or ($ext==".3g2") or ($ext==".mp4") or ($ext==".mp3") or ($ext==".wav") or ($ext==".mid")){
	if($_FILES['uploadedfile']['size'] > 10485760){
    	echo  "File too large!";
		echo "Maximum size for this extension is 10MB";
		die( "<p><a href=\"Home.php\">Try Again</a></p>");
	}
}else if(($ext==".gif") or ($ext==".jpg") or ($ext==".jpx") or ($ext==".jpe") or ($ext==".jpeg") or ($ext==".png") or ($ext==".bmp")){
	if($_FILES['uploadedfile']['size'] > 20971520){
    	echo  "File too large!";
		echo "Maximum size for this extension is 2MB";
		die( "<p><a href=\"Home.php\">Try Again</a></p>");
	}
}else if(($ext==".zip") or (!$ext==".arc") or (!$ext==".arg") or (!$ext==".czip")){
	if($_FILES['uploadedfile']['size'] > 31457280){
    	echo  "File too large!";
		echo "Maximum size for this extension is 3MB";
		die( "<p><a href=\"Home.php\">Try Again</a></p>");
	}
}else if(($ext==".doc") or (!$ext==".xls") or (!$ext==".mdb") or (!$ext==".ppt")){
	if($_FILES['uploadedfile']['size'] > 5242880){
    	echo  "File too large!";
		echo "Maximum size for this extension is 5MB";
		die( "<p><a href=\"Home.php\">Try Again</a></p>");
	}
}else if(($ext==".txt") or (!$ext==".rtf")){
	if($_FILES['uploadedfile']['size'] > 1048576){
    	echo  "File too large!";
		echo "Maximum size for this extension is 5MB";
		die( "<p><a href=\"Home.php\">Try Again</a></p>");
	}
}

//new file name example for a profile image of a user

//Get the users ip.
$ip="";

global $_SERVER;
if ($_SERVER['HTTP_X_FORWARD_FOR']) //stupid proxies! :P
{
	$ip =  $_SERVER['HTTP_X_FORWARD_FOR']; //get there real ip hehe
}else {
	$ip =  $_SERVER['REMOTE_ADDR']; //they dont use a proxy :)
}

$newfile = Rand(1,9999999999) . "_" . $ip . "_" . $_FILES['uploadedfile']['name'];

// move the file to the final destination
$target_loc = $target_path . basename($newfile);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_loc)) {
     echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
	 echo "<p>To link to your file please use <b>http://www.picminder.net/uploads/". $newfile . "</b></p>";
	 echo "<p>To view your file please goto <b>http://www.picminder.net/uploads/browsefile.php?file=". $newfile . "</b></p>";
	 echo "<p>We reserve the right to delete any file on our server.</p>"; 
	 die( "<p><a href=\"home.php\">Upload Another</a></p>");
	 $endHTML = "    </tr>
  </table>
  <p align=\"center\" class=\"style1 style2\"> </p>
  </div>
</body>";
	echo $endHTML;
} else{
     echo "There was an error uploading the file, please try again!";
	 die( "<p><a href=\"home.php\">Try Again</a></p>");
	 $endHTML = "    </tr>
  </table>
  <p align=\"center\" class=\"style1 style2\"> </p>
  </div>
</body>";
	echo $endHTML;
}
?>

whenever I try to upload a file it runs sends this message:

Code:
There was an error uploading the file, please try again!

That message is located in the final section of php code:

PHP:
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_loc)) {
     echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
	 echo "<p>To link to your file please use <b>http://www.picminder.net/uploads/". $newfile . "</b></p>";
	 echo "<p>To view your file please goto <b>http://www.picminder.net/uploads/browsefile.php?file=". $newfile . "</b></p>";
	 echo "<p>We reserve the right to delete any file on our server.</p>"; 
	 die( "<p><a href=\"home.php\">Upload Another</a></p>");
	 $endHTML = "    </tr>
  </table>
  <p align=\"center\" class=\"style1 style2\"> </p>
  </div>
</body>";
	echo $endHTML;
} else{
     echo "There was an error uploading the file, please try again!";
	 die( "<p><a href=\"home.php\">Try Again</a></p>");
	 $endHTML = "    </tr>
  </table>
  <p align=\"center\" class=\"style1 style2\"> </p>
  </div>
</body>";
	echo $endHTML;
}

But I cant find the error, could someone have a look at it for me please?

help
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Try this, I ran it without any errors...

PHP:
<html>
<head>
<title>Uploading</title>
</head>
<body bgcolor="#CCCCCC">
<title>Uploading</title>
<div align="center">
<table width="200" border="1" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td>
<p>
<span class="style1 style2"><img src="Images/Banner.gif" width="600" height="200" border="0" usemap="#Map"></span>
<map name="Map">
<area shape="rect" coords="231,47,287,92" href="Search.php">
<area shape="rect" coords="297,49,350,92" href="home.php">
<area shape="rect" coords="357,48,414,93" href="terms.php">
<area shape="rect" coords="423,48,485,93" href="contact.php">
<area shape="rect" coords="491,47,571,90" href="http://1.myfreebulletinboard.com/index.php?http://1.myfreebulletinboard.com/index.php?mforum=picminder">
</map>
</p>
<?php

// Where the file is going to be placed temporarly
$target_path = '/';
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
$target_path = './uploads/';
$oldfile =  basename($_FILES['uploadedfile']['name']);
$ext = strrchr($_FILES['uploadedfile']['name'], '.');

if((!$ext==".gif")&&(!$ext==".zip")&&(!$ext==".jpg")&&(!$ext==".jpx")&&(!$ext==".jpe")&&(!$ext==".jpeg")&&(!$ext==".png")&&(!$ext==".bmp")&&(!$ext==".wmv")&&(!$ext==".avi")&&(!$ext==".mpg")&&(!$ext==".mov")&&(!$ext==".asf")&&(!$ext==".asx")&&(!$ext==".swf")&&(!$ext==".3g2")&&(!$ext==".mp4")&&(!$ext==".mp3")&&(!$ext==".wav")&&(!$ext==".mid")&&(!$ext==".gz")&&(!$ext==".arc")&&(!$ext==".arg")&&(!$ext==".czip")&&($ext==".doc")&&(!$ext==".xls")&&(!$ext==".mdb")&&(!$ext==".ppt")&&(!$ext==".txt")&&(!$ext==".rtf")) {
?>
Dissallowed File Extension!
<br>
<p>
Allowed extensions are .zip, .gif, .bmp, .jpg, .png, .wmv, .avi, .mpg, .mov, .asf, .asx, .swf, .3g2, .mp4, .mp3, .wav and .mid
</p>
<p><a href='Home.php'>Try Again</a></p>
<?php
}else{
if(($ext==".wmv") or ($ext==".avi") or ($ext==".mpg") or ($ext==".mov") or ($ext==".asf") or ($ext==".asx") or ($ext==".swf") or ($ext==".3g2") or ($ext==".mp4") or ($ext==".mp3") or ($ext==".wav") or ($ext==".mid")) {
    if($_FILES['uploadedfile']['size'] > 10485760){
?>
File too large!
<br>
Maximum size for this extension is 10MB.
<br>
<p><a href='Home.php'>Try Again</a></p>
<?php
}
}else{
if(($ext==".gif") or ($ext==".jpg") or ($ext==".jpx") or ($ext==".jpe") or ($ext==".jpeg") or ($ext==".png") or ($ext==".bmp")) {
    if($_FILES['uploadedfile']['size'] > 20971520){
?>
File too large!
<br>
Maximum size for this extension is 2MB
<br>
<p><a href='Home.php'>Try Again</a></p>
<?php
}
}else{
if(($ext==".zip") or (!$ext==".arc") or (!$ext==".arg") or (!$ext==".czip")) {
    if($_FILES['uploadedfile']['size'] > 31457280) {
?>
File too large!<br>Maximum size for this extension is 3MB
<br>
<p><a href='Home.php'>Try Again</a></p>
<?php
}
}else{
if(($ext==".doc") or (!$ext==".xls") or (!$ext==".mdb") or (!$ext==".ppt")){
    if($_FILES['uploadedfile']['size'] > 5242880){
?>
File too large!
<br>
Maximum size for this extension is 5MB
<br>
<p><a href='Home.php'>Try Again</a></p>
<?php
}
}else{
if(($ext==".txt") or (!$ext==".rtf")) {
    if($_FILES['uploadedfile']['size'] > 1048576) {
?>
File too large!
<br>
Maximum size for this extension is 5MB
<br>
<p><a href='Home.php'>Try Again</a></p>
<?php
                 }
              }
           }
        }
     }
  }
}
global $_SERVER;

if ($_SERVER['HTTP_X_FORWARD_FOR']) //stupid proxies! :P
{
$ip =  $_SERVER['HTTP_X_FORWARD_FOR']; //get there real ip hehe
}else {
$ip =  $_SERVER['REMOTE_ADDR']; //they dont use a proxy :)
}

$ip = "";

$newfile = Rand(1,9999999999) . "_" . $ip . "_" . $_FILES['uploadedfile']['name'];
$target_loc = $target_path . basename($newfile);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_loc))
{
?>
The file <?php echo basename( $_FILES['uploadedfile']['name']); ?> has been uploaded.
<br>
<p>To link to your file please use <b>http://www.picminder.net/uploads/
<?php echo '$newfile'; ?></b>
</p>
<p>To view your file please goto <b>http://www.picminder.net/uploads/browsefile.php?file=
<?php echo '$newfile'; ?></b>
</p>
<p>We reserve the right to delete any file on our server.</p>
<p><a href='home.php'>Upload Another</a></p>
<?php
}else{
?>
There was an error uploading the file, please try again!
<br>
<p><a href='home.php'>Try Again</a></p>
<?php
}
?>
</body>
</html>
 
Last edited:
0
Close
hmmm still wont work..

ive made it echo the old file name (to see if thats the problem) and there isnt an old file name, i used the php:

PHP:
echo "Old Filename: " . $oldfile;

to get the output:

Code:
Old Filename:

so for some reason it cant get the old filename..
 
0
Close
Mikor said:
hmmm still wont work..

ive made it echo the old file name (to see if thats the problem) and there isnt an old file name, i used the php:

PHP:
echo "Old Filename: " . $oldfile;

to get the output:

Code:
Old Filename:

so for some reason it cant get the old filename..
PHP:
<?php

echo "Old Filename: "." $oldfile";

?>
 
0
Close
nope, tried that, cant get the old filename for some reason..
 
0
Close
SecondVersion said:
PHP:
<?php

echo "Old Filename: "." $oldfile";

?>

makes no odds doing it your way or his way. You dont need quotes around a variable. With your example you were just as well doing:-


PHP:
echo "Old Filename: $oldfile";
 
0
Close
ok, off the topic of variables and back onto the topic of my script, it still wont work, and I cant see why it wont..
 
0
Close
you are hosting it on your own computer or with a host ? maybe they have some limititations for file uploading
 
0
Close
also which version of php is being ran
 
0
Close
its on my pc and its the latest version of php, also heres the code for the form on the page before, that could be the problem:

Code:
        <form name="form" method="get" action="upload.php">
          <table width="414" border="0">
            <tr>
              <td width="158"><span class="style3">File Location: </span></td>
              <td width="246"><input name="uploadedfile" type="file" id="uploadedfile"></td>
            </tr>
          </table>
          <p align="center">
            <input type="submit" name="Submit" value="Upload File">
          </p>
          <ul class="style3"><li><div align="left"><font align="center" color="#000000"><strong>Upload media, images, archives, office and text files for free! </strong></font></div>
            </li>
            <li>
              <div align="left"><font align="center" color="#000000"><strong>Image Files - maximum 2mb</strong></font></div>
            </li>
            <li>
              <div align="left"><strong>Media Files</strong>  <span class="style2"><font align="center"><strong>- maximum 10mb</strong></font></span></div>
            </li>
            <li><strong>Archive Files - maximum 3mb</strong></li>
            <li><strong>Office Files - maximum 5mb</strong></li>
            <li><strong>Text Files - maximum 1mb</strong></li>
            <li><strong>For a full list of supported file extensions click <a href="extensions.php">here</a>.</strong></li>
          </ul>
      </form>
 
0
Close
the php code isnt a problem. Its your form.

in the form tag:

Code:
ENCTYPE="multipart/form-data"
 
0
Close
ok, can you post what the form should be please?
 
0
Close
Code:
<form name="form" method="get" ENCTYPE="multipart/form-data" action="upload.php">

or
Code:
 <form name="form" method="post" ENCTYPE="multipart/form-data" action="upload.php">
 
0
Close
thanks!

however, when I posted the upload code with the domain name in it (not yet regged by me) www.netminder.com someone regged it... so apart from that everythings ok, i'll have to find a new domain that I like though..
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back