Jump to content

Hi. Need help with image hosting script.


Dirtbagz89

Recommended Posts

Hello. I just downloaded a free image hosting script.

 

I'd like it to be able to upload .psd files but it currently doesn't.

 

I think this is the code to change it but I'm not good with PHP.

 

<?
include "config.php";

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) {
        echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; }
if(($HTTP_POST_FILES['userfile']['type']=="image/gif") || 
($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {

        if (file_exists("./".$path . $HTTP_POST_FILES['userfile']['name'])) {
                echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; }

//generate random number
$zufall = rand(1,9999);
$fupl = "$zufall";

        $res = copy($HTTP_POST_FILES['userfile']['tmp_name'], "./".$path .$fupl .$HTTP_POST_FILES['userfile']['name']);

        if (!$res) { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; } else {
        ?>
<br>

<?
//set url variable
$domst = "";
$drecks = "/";
$imgf = $fupl.$HTTP_POST_FILES['userfile']['name'];
$thbf = $tpath.$imgf;
$urlf = $domst .$domain .$drecks .$path .$imgf;


//create thumbnails
function createthumb($name,$filename,$new_w,$new_h){
$system=explode('.',$name);
if (preg_match('/jpg|jpeg|JPG/',$system[1])){
	$src_img=imagecreatefromjpeg($name);
}
if (preg_match('/png|PNG/',$system[1])){
	$src_img=imagecreatefrompng($name);
}
if (preg_match('/gif|GIF/',$system[1])){
	$src_img=imagecreatefromgif($name);
}

$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}

$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 


if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename); 
} 
if (preg_match("/gif/",$system[1]))
{
imagegif($dst_img,$filename);
}
else {
imagejpeg($dst_img,$filename); 
}
imagedestroy($dst_img); 
imagedestroy($src_img); 
}

createthumb($path.$imgf,$tpath.$imgf,$tsize,$tsize);
?>


<body bgcolor="#ffffff">
<center>
<div class="support" id="agreement">
<table border='0' >
<link rel="STYLESHEET" type="text/css" href="style.css">
<FORM action="nowhere" method="post"><title>iMage-Net</title>
<center><?
include "ads.php";
?>
<tr><td>URL:</td><td><input type="text" name="thetext" size="60" value='<? echo $domst .$domain .$drecks ?>viewer.php?id=<? echo $imgf; ?>'></td></tr>
<tr><td>DIRECT URL:</td><td><input type="text" name="thetext" size="60" value="<? echo $urlf; ?>"></td></tr>
<tr><td>HTML:</td><td><input type="text" name="thetext" size="60" value="<a href='<? echo $domst .$domain .$drecks; ?>viewer.php?id=<? echo $imgf; ?>'><img src='<? echo $domst.$domain.$drecks.$tpath.$imgf; ?>'></a>"></td></tr>
<tr><td>BBCode:</td><td><input type="text" name="thetext" size="60" value="[url=<? echo $domst .$domain .$drecks; ?>viewer.php?id=<? echo $imgf; ?>][img=<? echo $domst.$domain.$drecks.$tpath.$imgf; ?>][/url]"></td></tr>
<tr><td>IMAGE:</td><td>                 <img src='<? echo $thbf ?>'>               </td></br><a href="javascript:history.go(-1);" title="go back to previous page">Back</a> </div></tr></td></tr>
<?

}
} else { echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"><link rel='stylesheet' href='style.css' type='text/css'><div class='support' id='agreement'><p><center>You selected a wrong filetype!</font></center></div><br>\n"; exit; }
}
?>
</table>
<br><br>
</body>

Link to comment
https://forums.phpfreaks.com/topic/37224-hi-need-help-with-image-hosting-script/
Share on other sites

Change HTTP_POST_FILES to just FILES, for one.

Secondly, a psd is not an image, so PHP won't be able to create a thumbnail of it. It's a very complex file, not an image.

On Preview: The GD Library is how PHP manipulates Images.

 

The script could be modified to allow people to upload and host psd files, but not to create image previews (AFAIK.)

Change HTTP_POST_FILES to just FILES, for one.

Secondly, a psd is not an image, so PHP won't be able to create a thumbnail of it. It's a very complex file, not an image.

On Preview: The GD Library is how PHP manipulates Images.

 

The script could be modified to allow people to upload and host psd files, but not to create image previews (AFAIK.)

 

Would that be easy to do?

I think you're missing some of it. I changed what was applicable, but like I said, I think the end is missing some code.

Try this, and add what was missing if it was, etc.

<?
include "config.php";

if (!isset($_FILES['userfile'])) exit;

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {

if ($_FILES['userfile']['size']>$max_size) {
	echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; 
}
if(($_FILES['userfile']['type']=="image/gif") || ($_FILES['userfile']['type']=="image/pjpeg") || ($_FILES['userfile']['type']=="image/jpeg") || ($_FILES['userfile']['type']=="image/png") || ($_FILES['userfile']['type'] == 'image/x-photoshop') || ($_FILES['userfile']['type'] == 'application/photoshop')){
	if (file_exists("./".$path . $_FILES['userfile']['name'])) {
		echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; 
	}
	//generate random number
	$zufall = rand(1,9999);
	$fupl = "$zufall";

        $res = copy($_FILES['userfile']['tmp_name'], "./".$path .$fupl .$_FILES['userfile']['name']);

        if (!$res) { 
		echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">Didn't work, please try again</font><br>\n"; exit; 
	} else {
       	 	?>
		<br>

		<?
		//set url variable
		$domst = "";
		$drecks = "/";
		$imgf = $fupl.$_FILES['userfile']['name'];
		$thbf = $tpath.$imgf;
		$urlf = $domst .$domain .$drecks .$path .$imgf;


		//create thumbnails
		function createthumb($name,$filename,$new_w,$new_h){
			$system=explode('.',$name);
			if (preg_match('/jpg|jpeg|JPG/',$system[1])){
				$src_img=imagecreatefromjpeg($name);
			}
			if (preg_match('/png|PNG/',$system[1])){
				$src_img=imagecreatefrompng($name);
			}
			if (preg_match('/gif|GIF/',$system[1])){
				$src_img=imagecreatefromgif($name);
			}

			$old_x=imageSX($src_img);
			$old_y=imageSY($src_img);
			if ($old_x > $old_y) {
				$thumb_w=$new_w;
				$thumb_h=$old_y*($new_h/$old_x);
			}
			if ($old_x < $old_y) {
				$thumb_w=$old_x*($new_w/$old_y);
				$thumb_h=$new_h;
			}
			if ($old_x == $old_y) {
				$thumb_w=$new_w;
				$thumb_h=$new_h;
			}

			$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
			imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 


			if (preg_match("/png/",$system[1])){
				imagepng($dst_img,$filename); 
			} 
			if (preg_match("/gif/",$system[1])){
				imagegif($dst_img,$filename);
			}else {
				imagejpeg($dst_img,$filename); 
			}
			imagedestroy($dst_img); 
			imagedestroy($src_img); 
		}

		if(($_FILES['userfile']['type'] == 'image/x-photoshop') || ($_FILES['userfile']['type'] == 'application/photoshop')){
			//No thumbnail
		}else{
			createthumb($path.$imgf,$tpath.$imgf,$tsize,$tsize);
		}
		?>


		<body bgcolor="#ffffff">
		<center>
		<div class="support" id="agreement">
		<table border='0' >
		<link rel="STYLESHEET" type="text/css" href="style.css">
		<FORM action="nowhere" method="post"><title>iMage-Net</title>
		<center><?
		include "ads.php";
		?>
		<tr><td>URL:</td><td><input type="text" name="thetext" size="60" value='<? echo $domst .$domain .$drecks ?>viewer.php?id=<? echo $imgf; ?>'></td></tr>
		<tr><td>DIRECT URL:</td><td><input type="text" name="thetext" size="60" value="<? echo $urlf; ?>"></td></tr>
		<tr><td>HTML:</td><td><input type="text" name="thetext" size="60" value="<a href='<? echo $domst .$domain .$drecks; ?>viewer.php?id=<? echo $imgf; ?>'><img src='<? echo $domst.$domain.$drecks.$tpath.$imgf; ?>'></a>"></td></tr>
		<tr><td>BBCode:</td><td><input type="text" name="thetext" size="60" value="[url=<? echo $domst .$domain .$drecks; ?>viewer.php?id=<? echo $imgf; ?>][img=<? echo $domst.$domain.$drecks.$tpath.$imgf; ?>][/url]"></td></tr>
		<tr><td>IMAGE:</td><td>                 <img src='<? echo $thbf ?>'>               </td></br><a href="javascript:history.go(-1);" title="go back to previous page">Back</a> </div></tr></td></tr>
		<?

		}
	} else { 
		echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\"><link rel='stylesheet' href='style.css' type='text/css'><div class='support' id='agreement'><p><center>You selected a wrong filetype!</font></center></div><br>\n"; exit; }
	}
	?>
	</table>
	<br><br>
	</body>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.