file upload script

nightscream

New Member
Messages
948
Reaction score
0
Points
0
I'm creating my own upload script but It won't work
if I want to upload something i get
File '' not uploaded
It's something with the $_FILES i think but don't know how to fix it
PHP:
if( isset( $_POST['Upload'] )) {
	$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "images/";
	$MaxFileSize = 800000000;
	$filename = $_FILES['file']['name'];
	$filesize = $_FILES['file']['size'];
	$filetmpname = $_FILES['file']['tmp_name'];
	$allowed_types = array( "jpg", "gif", "png" );
	$filetype = substr($filename, -3, 3);
	//$Thumb = $_POST['Thumbnail'];
	//$Water = $_POST['Watermarking'];
	
	if($filename) {
	echo 'test';
	$error = 0;
		if(($filesize > $MaxFileSize) | $filesize = 0 ) {
			$error = 1;
			$errmsg .= "Your File is to large, (Max File size: 8MB)";
		}
		if( !in_array( $filetype, $allowed_types )) {
			$error = 1;
			$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
		}else  {
			$error = 0;
		}
		if( $error = 1 ) {
			die( "$errmsg" );
		}else{				
			$num = rand( 1, 9999 );
			$new_filename = $num.$filename;
			$upload = move_uploaded_file($filetmpname, "$upload_dir.$new_filename");
			if($Thumb = 1 ) {
				CreateThumb($filetmpname);
			}
			if($Water = 1 ) {
				CreateWatermark($filetmpname);
			}
			if( $upload ) {
				echo 'Upload Succesfull';
				//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
			}else {
				die( "Cound not upload the file, please try again" );
			}
		}
	}else{
		echo "File '$filename' not uploaded";
	}
}
?>
 
Last edited:

Chris Z

Active Member
Messages
5,603
Reaction score
0
Points
36
darn...i wish i knew more about php, i can't figure out why it's not working, just wait til bryon comes lol
 

nightscream

New Member
Messages
948
Reaction score
0
Points
0
i forgot the enctype= thingy in <form>
PHP:
if( isset( $_POST['Upload'] )) {
    $upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/test/images/";
    $MaxFileSize = 8192000;
    $filename = $_FILES['file']['name'];
    $filesize = $_FILES['file']['size'];
    $filetmpname = $_FILES['file']['tmp_name'];
    $allowed_types = array( "jpg", "gif", "png" );
    $filetype = substr($filename, -3, 3);
    
    if($filename) {
    $error = 0;
        if(($filesize > $MaxFileSize) || $filesize = 0 ) {
            $error = 1;
            $errmsg .= "Your File is to large, (Max File size: 8MB)";
        }
        if( !in_array( $filetype, $allowed_types )) {
            $error = 1;
            $errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
        }else  {
            $error = 0;
        }
        if( $error == 1 ) {
            die( "$errmsg" );
        }else{                
            $num = rand( 1, 9999 );
            $new_filename = $num.$filename;
            $upload = move_uploaded_file($filetmpname, "$upload_dir$new_filename");
            if( $upload ) {
                echo 'Upload Succesfull';
                //echo "<meta http-equiv='refresh' content='0; URL=?image=$upload_dir$new_filename'>";
            }else {
                die( "Cound not upload the file, please try again" );
            }
        }
    }else{
        echo "File '$filename' not uploaded";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<center>
<form enctype="multipart/form-data" action="uploadform.php" method="post">
<input type="file" name="file"><br />
JPG, GIF, PNG uploadable files.<br />
<input type="checkbox" name="Thumbnail"> Thumbnails option<br />
<input type="checkbox" name="Watermarking"> Watermarking option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>
 
Last edited:

XxUnknownxX

New Member
Messages
22
Reaction score
0
Points
0
cool thats a good script i got a question 4 u do u know how to make a log in script thbt logs u to the forum
 

nightscream

New Member
Messages
948
Reaction score
0
Points
0
You mean on your regular website a login box and if you login you will be rederected to the forum and you are logged in?
 

Conor

New Member
Messages
3,570
Reaction score
0
Points
0
I was kind of looking for something similar like that. I am building a website and want to insert a login box on the homepage and when you login and click on the forums link, you are logged in already as a result of the information you submitted on the homepage.
 

gjohack19

New Member
Messages
2
Reaction score
0
Points
0
i forgot the enctype= thingy in <form>
PHP:
if( isset( $_POST['Upload'] )) {
    $upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/test/images/";
    $MaxFileSize = 8192000;
    $filename = $_FILES['file']['name'];
    $filesize = $_FILES['file']['size'];
    $filetmpname = $_FILES['file']['tmp_name'];
    $allowed_types = array( "jpg", "gif", "png" );
    $filetype = substr($filename, -3, 3);
    
    if($filename) {
    $error = 0;
        if(($filesize > $MaxFileSize) || $filesize = 0 ) {
            $error = 1;
            $errmsg .= "Your File is to large, (Max File size: 8MB)";
        }
        if( !in_array( $filetype, $allowed_types )) {
            $error = 1;
            $errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
        }else  {
            $error = 0;
        }
        if( $error == 1 ) {
            die( "$errmsg" );
        }else{                
            $num = rand( 1, 9999 );
            $new_filename = $num.$filename;
            $upload = move_uploaded_file($filetmpname, "$upload_dir$new_filename");
            if( $upload ) {
                echo 'Upload Succesfull';
                //echo "<meta http-equiv='refresh' content='0; URL=?image=$upload_dir$new_filename'>";
            }else {
                die( "Cound not upload the file, please try again" );
            }
        }
    }else{
        echo "File '$filename' not uploaded";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<center>
<form enctype="multipart/form-data" action="uploadform.php" method="post">
<input type="file" name="file"><br />
JPG, GIF, PNG uploadable files.<br />
<input type="checkbox" name="Thumbnail"> Thumbnails option<br />
<input type="checkbox" name="Watermarking"> Watermarking option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>

thank you for share
 
Top