OK I decided to retry it into another way.. This is my code the bad part is now it keep saying invalid file size.
<?php
session_start();
include "connect.php";
if ( $_POST[ "submit" ] ) {
if ( $_SESSION[ "name" ] ) {
$name = $_FILES[ "file" ][ "name" ];
$type = $_FILES[ "file" ][ "type" ];
$size = $_FILES[ "file" ][ "size" ];
$tmp_name = $_FILES[ "file" ][ "tmp_name" ];
$error = $_FILES[ "file" ][ "error" ];
if ( $type == "image/jpeg" || $type == "image/gif" ) {
if ( $size > 1100000 && $size < 1700000 ) {
if ( $error > 0 ) {
echo "Error!!!!!!" . $error;
} else {
if ( file_exists( "upload/" . $name ) ) {
echo $name . " already exists.";
}
}
} else {
$location = "upload/" . $name;
move_uploaded_file( $tmp_name , $location );
$user = $_SESSION[ "name" ];
$sqlcode = mysql_query( "INSERT INTO tblFile (id,user,location) VALUES ('','$user','$location')" );
echo "<a href='$location'>Click here to view your image.</a>";
}
}
} else {
echo "Please check the size of your File..";
}
} else {
echo "Invalid file format.";
}
?>
the index is:
<?php
session_start();
$_SESSION["name"] = "Admin";
?>
<!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" lang="en">
<head>
<title>File Upload</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
Select File: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"/>
<input name="Submit" type="submit" value="Upload File">
</form>
If it is not one thing with this file/upload it is something else. I still have to be able to user uploads a .png or .jpg file, resize the image to a thumbnail and keep a copy of both the thumbnail and regular size image in a folder. And be able to insert the data into a new table in your database. I think I am alittle closer than before.
Try this, I have reconstructed and ‘clean’ your code.
And also, apply changes suggested by @jakenoble.
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"/>