PHP Upload Image Script not working?

Sammy G

New member
This script should allow a user to upload an image, When I click on submit button nothing happens :( here is the script:
upload_image.php
<?
session_start();
require_once("php_inc.php");
include("header_inc.php");
db_connect();
//Function to Upload Image to Profile
if (session_is_registered(username))
{
$valid_user = $_SESSION[username];
do_html_heading("Image upload");
member_menu();
?>
<h2>Upload image</h2>


<?
print "<font class='text'>Upload limit is " . floor($set_piclimit / 1024) . " kb.</font><p />";

if (!isset($_POST['submit']))
{
print "From here you can upload a picture to your profile. Please note that the image
can be no larger than " . floor($set_piclimit / 1024) . " in size, and will be scaled
down to fit as thumbnail.";
}

print "<form method='POST' action='upload_image.php' enctype='multipart/form-data'>";
?>

<INPUT TYPE="hidden" name="pictures_siteid" value="<? echo $pictures_siteid ?>" />
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="<? echo $set_piclimit ?>" />

<?
if (isset($_POST['submit']))
{

if($photo_size)
{
// Get file extension
$ext=substr($photo_name,-4);
$file_without_ext=substr($photo_name,0,-4);
// Allowed file takes
if (strcasecmp($ext,".jpg") || strcasecmp($ext,".gif"))
{

if(is_uploaded_file($photo))
{
$rand = rand(200,19999999);
$photo_name = $rand . $photo_name;
$photo_name_large = $rand . $file_without_ext . "_large" . $ext;
$photo_name_small = $rand . $file_without_ext . "_small" . $ext;
move_uploaded_file($photo,"upload_images/$photo_name");


if ($set_magic)
{

// your own path in the strings below. On Linux, you can normally just type convert


$command = "convert -quality $set_magic_q -size $set_orgsize -scale $set_orgsize upload_images/$photo_name upload_images/$photo_name";
$res = exec($command);


$command = "convert -quality $set_magic_q -size $set_thmbsize -scale $set_thmbsize upload_images/$photo_name upload_images/$photo_name_small";
$res = exec($command);

}


// Tell the database that picture is uploaded
$string = "UPDATE user set image = '$photo_name' where username = '$valid_user'";
$result_done= mysql_query($string);


if ($result_done)
{
print("<p />Done!<br \>The image is uploaded !<p />");
print("<img src='upload_images/$photo_name'>");
}

}
}
else
{
die("Please, only .gif or .jpg images.");
}
}
else if($photo_name != "" && $photo_size == "0")
{
die("The picture is 0 kb.");
}
else
{
print "No picture choosen for upload.";
}


}
?>
<p />
<br />
Image file (click Browse to look on your computer for image):<br />
<input name="photo" type="file" /><br />
<input type="submit" name="submit" value="Upload image" />
</form>

<?
}
require("footer_inc.php");
?>

Variables included in settings_inc.php
<?
//Settings for Image uploader
$set_thmbsize="100x100";
$set_orgsize="250x250";
$set_piclimit="90000";
$set_banlist="";
$set_magic="on";
$set_magic_q="80";
$set_magic_q="80";
?>
any suggestions would be appreciated
 
<?
/********************************
files.class.php
********************************/
class files{
var $Error;
var $goback;

function files(){
}

function file_form($UserInput){
echo "<div align=\"center\"><form method=\"post\" action=\"$_SERVER[PHP_SELF]\" name=\"FileUpload\" enctype=\"multipart/form-data\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" id=\"LoginTable\" bgcolor=\"#000000\" align=\"center\"><tr><td id=\"Upload\"><strong>**Information**</strong><br><i>Max upload file size is 10MB</i><br><br></td></tr><tr><td id=\"Upload\"><div align=\"center\">File to upload: <input type=\"file\" name=\"file_to_upload\"></div></td></tr><tr><td id=\"Upload\"><div align=\"center\">Access: <select name=\"Access\" id=\"select\"><option value=\"0\">Private</option><option value=\"1\">Public</option></select></div></td></tr><tr><td id=\"Upload\"><div align=\"center\">File Comments:</div></td></tr><tr><td colspan=\"2\" id=\"Upload\"><div align=\"center\"><textarea name=\"FileComments\" cols=\"50\" rows=\"10\"></textarea></div></td></tr><tr><td id=\"Upload\" colspan=\"2\"><div align=\"center\"><input type=\"submit\" value=\"Submit\"> <input type=\"reset\" value=\"Reset\"></div></td></tr></table></form></div>";
}

function add_file($UserInput){
require_once('static.class.php');
if(file_exists("upload/" . $_FILES['file_to_upload']['name']))
{
$this->file_form($UserInput);
echo "<div align=\"center\"><font color=\"red\">The file already exists! Delete first!<br>Try again or $this->goback!</font></div>";
$this->Error == true;
exit;

}
else
{
//Add the file
$this->move_temp_file = move_uploaded_file($_FILES['file_to_upload']['tmp_name'], "upload/" . $_FILES['file_to_upload']['name']);
if(!$this->move_temp_file)
{
$this->file_form($UserInput);
echo "<div align=\"center\"><font color=\"red\">There was a problem uploading your file!<br>Try again or $this->goback!<br>Contact support!</font></div>";
$this->Error == true;
exit;
}
else
{
//Add file information to database
//Generate File ID
$this->file_ID = md5($_SESSION['Path'] . "/" . $_FILES['file_to_upload']['name'] . date($_SESSION['UNIX_EP']));
$this->file_path = $_SESSION['Path'] . "/" . $_FILES['file_to_upload']['name'];
$Nfile_name = $_FILES['file_to_upload']['name'];
$Nfile_type = $_FILES['file_to_upload']['type'];
$Nfile_size = $_FILES['file_to_upload']['size'];

$IVal = $_FILES['file_to_upload']['size'];
$file_size = new static_class();
$file_size->StaticFSize($IVal);
$this->read_file_size = $file_size->FDS;

$this->query_string = "INSERT INTO files (id, UID, File_Name, File_ID, File_Type, File_Path, File_Access, File_DTG, File_Size, Read_File_Size, File_Count, Comments) VALUES('0','$_SESSION[UID]', '$Nfile_name','$this->file_ID','$Nfile_type','$this->file_path','$UserInput[Access]','" . date($_SESSION['DTG']) . "','$Nfile_size','$this->read_file_size','0','" . addslashes($UserInput['FileComments']) . "')";
$this->query = mysql_query($this->query_string);
if(!$this->query)
{
$this->delete_file = unlink("upload/" . $_FILES['file_to_upload']['name']);
$this->file_form($UserInput);
$space_left_message = ($this->space_left <= "0") ? "You do not have any space left" : "Space left:" . $file_size->FDS;
echo "<div align=\"center\"><font color=\"red\">Error adding file to database! No file uploaded! $this->goback</font></div>";
$this->Error == true;
exit;
}
else
{
$this->file_form($UserInput);
echo "<div align=\"center\"><font color=\"red\">File upload complete!</font></div>";
$this->Error == false;
}

}
}
}



function validate_file($UserInput){
require_once('static.class.php');
$this->goback = "<a href=javascript:history.go(-1)><font color=red size=-2>(Go Back)</font></a>";
$this->max_upload_size=pow(1024,2)*10;

//Calculate the file size
$file_size = new static_class();
$IVal = $_FILES['file_to_upload']['size'];
$file_size->StaticFSize($IVal);
$UserInput['file_size'] = $file_size->FDS;

//Check to see if user has enough space left
$this->max_disk_space = pow(1024,2)*10;
//Add all file s
 
Back
Top