Uploading Png

Forum
Last Post
Threads / Messages

SieghartZeke

Member
Member
Joined
Oct 4, 2009
Messages
149
Points
0
Age
29
Mysidian Dollar
6,621
I have Tried to Change the Code for uploading image .png
It Work but...the only problem is that when i create, and give the name...I Find This "Unknow Image 26-03-2010" Vut I add a name to the Image!!
Oh Also i find this error when i upload:
Warning: preg_replace() [function.preg-replace]: No ending delimiter '/' found in /home/a2394530/public_html/admuploadpic.php on line 303

Here my admuploadpic.php:
Code:
<?php

// **********************************************************************
// Rusnak PHP Adoptables Script
// Copyright 2009 Brandon Rusnak
// For help and support: http://www.rusnakweb.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************

// **********************************************************************
// This file allows the administrator to create a new adoptable...
// File ID: nadopt.php
// **********************************************************************


// Wake the sleeping giant

// **********************************************************************
// Basic Configuration Info
// **********************************************************************

include("inc/functions.php");
include("inc/config.php");

$themeurl = grabanysetting("themeurl");


// **********************************************************************
// Define our ads by calling getads()
// **********************************************************************

$ads = ""; // No Ads, because we're in the Admin CP...

// **********************************************************************
// Grab any dynamic article content from the content table
// **********************************************************************

$pagecontent = getsitecontent("index");
$article_title = $pagecontent[title];
$article_content = $pagecontent[content];
$article_content = nl2br($article_content);

// **********************************************************************
// Grab any settings that we will need for the current page from the DB
// **********************************************************************

$browsertitle = grabanysetting("browsertitle");
$sitename = grabanysetting("sitename");
$slogan = grabanysetting("slogan");

// **********************************************************************
// Check and see if the user is logged in to the site
// **********************************************************************

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

// **********************************************************************
// End Prepwork - Output the page to the user
// **********************************************************************

if($isloggedin == "yes"){

$group = getgroup();
$cancp = cancp($group);
$canedit = cando($group, "canmanageadopts");

if($cancp == "yes" and $canedit == "yes"){

// We are logged in and can access this page

// Set the user's prefix...

// The code to upload the actual file goes here...

// BEGIN FILE UPLOAD
	
$flag = 0; // Safety net, if this gets to 1 at any point in the process, we don't upload.

$filesize = $_FILES['uploadedfile']['size'];
$mimetype = $_FILES['uploadedfile']['type'];
$filename = $_FILES['uploadedfile']['name'];


$filename = htmlentities($filename);
$filesize = htmlentities($filesize);
$mimetype = htmlentities($mimetype);

//Default upload directory
$uploaddir = "picuploads/png";


//***************************************************************************
//First we determine if the file is a gif or a jpg by checking the extension

//First check and see if the file is a .gif file
$ispng = "no";

$whitelist = array(".png");
foreach ($whitelist as $ending) {

if(substr($filename, -(strlen($ending))) != $ending) {

//File is not a gif file, so let's do nothing right now
//When we check for if it is a jpg we will flag the file

}
else{
//The file IS a gif file, so we set the isgif to true
$ispng = "yes";

}
}

// Now we check if it is a .jpg file or not, because it is not a gif

if($isgif != "yes"){

$whitelist = array(".png");
foreach ($whitelist as $ending) {

if(substr($filename, -(strlen($ending))) != $ending) {

	if($flag == 0){
	$error = "The file type or extention you are trying to upload is not allowed!  
	You can only upload gif or jpg files to the server!";
	}

$flag++;
}
}

}

//***************************************************************************

//First generate a MD5 hash of what the new file name will be
//Force a file extention on the file we are uploading

//Now we create a hashed file name of the file and set the upload directory...

if($ispng == "yes"){

$date = date('Y-m-d');
$hashstring = $prefix."".$filename."_".$date;

$hashedfilename = md5($hashstring);
$hashedfilename = $hashedfilename.".png";
$target_path = "picuploads/png/";
$uploaddir = "picuploads/png";

}
else if ($ispng == "no" and $flag == 0){

//File is a jpg

$date = date('Y-m-d');
$hashstring = $prefix."".$filename."_".$date;

$hashedfilename = md5($hashstring);
$hashedfilename = $hashedfilename.".png";
$target_path = "picuploads/png/";
$uploaddir = "picuploads/png";

}
else{
$flag++; //Not sure what type of file we've got, so abort...
}


//SET TARGET PATH?
$target_path = $target_path . basename( $filename );


//Check for empty file
if($hashedfilename == ""){

	if($error == ""){
	$error = "No File Exists!";
	}

$flag = $flag + 1;

}

//Now we check that the file doesn't already exist.
$existname = $uploaddir."/".$hashedfilename;

if(file_exists($existname)){

if($flag == 0){
$error = "Your file already exists on the server!  
Please choose another file to upload or rename the file on your 
computer and try uploading it again!";
}

$flag = $flag + 1;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////


//Now we check the filesize.  If it is too big then we reject it


if($filesize > 153600){
//File is too large

if($flag == 0){
$error = "The file you are trying to upload is too large!  Files must be under 150 KB.";
}

$flag = $flag + 1;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//Check the mimetype of the file
if($mimetype != "image/png" and $mimetype != "image/png"){

if($flag == 0){
$error = "The file you are trying to upload does not contain expected data.
Are you sure that the file is a .gif or .jpg file?";
}

$flag = $flag + 1;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//Now that we checked the mime type client side, let's check it again server side...

$imageInfo = getimagesize($_FILES["uploadedfile"]["tmp_name"]); // note that we need to use the temporal name since it has not yet been moved  
if($imageInfo["mime"] != "image/png" and $imageInfo["mime"] != "image/png")  
{  
	if($error == ""){
	$error = "The file you are trying to upload does not contain expected data.
	Are you sure that the file is a .gif or .jpg file?";
	}

$flag++;

} 


////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

//All checks are done, actually move the file...

if($flag == 0){

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploaddir."/".$hashedfilename)) {
    

	if(@file_exists($uploaddir."/".$hashedfilename)){

	$article_title = "Success!";

	$article_content = "The file ".  basename( $filename ). " 
      has been uploaded successfully!  It will now appear in the drop down list of available adoptables images.";
	
	}	
	else{
      $article_title = "ERROR!";
	$article_content = "There was an error uploading the file, please try again!";

	}


} else{
    $article_title = "ERROR!";
    $article_content = "There was an error uploading the file, please try again!";

    
	
}

}
else {
$article_title = "ERROR!";
if($error != ""){
$article_content = $error;
}
else{
$article_content = "File Upload Failed!";
}
}

//More code here
//Done with upload, so insert data into database

//Grab the friendly name form data...

$ffn = $_POST["ffn"];
$ffn = preg_replace("/[^a-zA-Z0-9?40.]/", "", $ffn);
$ffn = secure($ffn);

if($ffn == ""){
$ffn = "Unknown Image :: ".$date;
}



// ** Actually insert the photo's information into the database ** 

$serverpath = $uploaddir."/".$hashedfilename;
$wwwpath = "http://www.".$domain."".$scriptpath."/".$serverpath;



if($flag == 0){

$query = "INSERT INTO ".$prefix."filesmap VALUES ('', '$serverpath', '$wwwpath','$ffn')";
mysql_query($query);

}

$article_content = $article_content."<br><br><b><u>What would you like to do now?</u></b><br><br>
<a href='admin.php?set=adopts&do=uploadimg'>Upload Another Image</a><br>
<a href='admin.php?set=adopts'>Manage Adoptables</a><br>
<a href='admin.php'>Admin CP Home</a>";


} //This bracket ends the check of whether or not this user can access the adopts portion of the ACP
else{

$article_title = "Access Denied";
$article_content = "Access Denied";

}



}
else{

$article_title = "Access Denied";
$article_content = "Access Denied";

}

// **********************************************************************
// Begin Template Definition
// **********************************************************************

//Define our current theme
$file = $themeurl;

// Do the template changes and echo the ready template
$template = file_get_contents($file);

$template = replace(':ARTICLETITLE:',$article_title,$template);
$template = replace(':ARTICLECONTENT:',$article_content,$template);
$template = replace(':ARTICLEDATE:',$article_date,$template);

$template = replace(':BROWSERTITLE:',$browsertitle,$template);
$template = replace(':SITENAME:',$sitename,$template);

//Define our links

if($cancp == "yes"){

//Admins see a custom set of links here...

$links = getadmlinks();

}
else{

$links = getlinks();

}

$template = replace(':LINKSBAR:',$links,$template);

//Get the content for the side bar...

$sidebar = getsidebar();
$template = replace(':SIDEFEED:',$sidebar,$template);

//Get the ad content...
$template = replace(':ADS:',$ads,$template);

//Get the slogan info
$template = replace(':SLOGAN:',$slogan,$template);


echo $template;

// **********************************************************************
// End Template Definition
// **********************************************************************



?>

Please, say to me where is the problem to fix...THANK YOU XD
 
i treid this on my mod, i couldnt do it either, so il use onl;y prehosted iamges..
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,132
Members
1,603
Latest member
Monako
BETA

Latest Threads

Top