Upload Script Hulp

Status
Niet open voor verdere reacties.

w00tare

Gebruiker
Lid geworden
10 jul 2009
Berichten
216
Hallo,

Ik heb sinds kort een upload script, nou kan ik wel een beetje php maar hier kom ik niet uit.
Ik mijn script werkt als volgt:

Gebruiker Upload File -> Nieuwe Naam(bijv: 9j3298fidj28ji29) -> Naam doorvoeren met image -> klaar

Nou heb ik een probleem, want sommige forum types (vbulletin,IPB) die accepteren geen IMG zonder extensie (.png .jpg etc)
Nou wil ik dat hij een extensie toevoegt aan de url.

De code om de image weertegeven als de URL aangeroepen word:

Code:
if (isset($_GET['di'])){
		$img_id = removeSymbols(end(explode('/',input($_GET['di']))));
		if ($db->item_exists('id',$img_id)){
			not_max_bandwidth($img_id);
			$img_address = get_image_address($img_id,'');
			$pathinfo = pathinfo($img_address);
			header('Content-type: image/'.strtolower($pathinfo['extension']));
			readfile($img_address);
			if(hotlink()) countSave($img_id,1);
			exit();
		}else
			notfound();
	}

En het deel wat de foto upload:

Code:
if(!$err_get_img) {
		        
                        // have being experimental with this previous: $newname = rand(0,number).time().rand(0,number);
			//new random name
				$newname = rand(0,number).time();

			//random delete ID
				$delete_id = md5(rand(0,7).rand(0,7).time().rand(0,14));

			//Image address
				$IMG_NAME = $newname.'.'.$path_info['extension'];
				$IMG_ADDRESS = $DIR_IMAGE.$IMG_NAME;

			//Thumb address
				$THUMB_NAME = $newname.'.'.$THUMB_SAVE_EXT;
				$THUMB_ADDRESS = $DIR_THUMB.$THUMB_NAME;
				$THUMB_MID_ADDRESS = $DIR_THUMB_MID.$THUMB_NAME;

			//Attempt to move the uploaded file to the upload folder
				if (@move_uploaded_file($file_tmp_name,$IMG_ADDRESS)) {

				// thumb
					$resizeObj = new resize($IMG_ADDRESS);
				// make thumb
					$resizeObj -> resizeImage($THUMB_MID_MAX_WIDTH, $THUMB_MID_MAX_HEIGHT, $THUMB_MID_OPTION);
					$resizeObj -> imageSaveQuality($THUMB_MID_QUALITY);
					$resizeObj -> saveImage($THUMB_MID_ADDRESS);
				// make small thumb
					$resizeObj -> resizeImage($THUMB_MAX_WIDTH, $THUMB_MAX_HEIGHT, $THUMB_OPTION);
					$resizeObj -> imageSaveQuality($THUMB_QUALITY);
					$resizeObj -> saveImage($THUMB_ADDRESS, $THUMB_QUALITY);

					if(file_exists($THUMB_ADDRESS) && file_exists($THUMB_MID_ADDRESS)){

						// alt text
						$alt = empty($_POST["alt"][$i]) ? $path_info['filename']:removeSymbols(input($_POST["alt"][$i]));

						if (isset($_POST['shorturl']) && $_POST['shorturl'] == 1 && $settings['SET_SHORT_URL_ON']){
							$shorturl = shorturl_url('http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$newname);
						}else{
							$shorturl = null;
						}

					// save image info to db
						$NEW_IMG_ITEM = array(	'id'		=> $newname,
												'name'		=> $file_name,
												'alt'		=> $alt,
												'added'		=> time(),
												'ext'		=> $path_info['extension'],
												'ip'		=> $_SERVER['REMOTE_ADDR'],
												'size'		=> $file_size,
												'deleteid'	=> $delete_id,
												'thumbsize' => @filesize($THUMB_MID_ADDRESS),
												'sthumbsize'=> @filesize($THUMB_ADDRESS),
												'private'	=> (isset($_POST['private'])?1:0),
												'shorturl'	=> $shorturl,
												);

						$db = new array_db($ADD_DB_IMG);
						if($db->add_row($NEW_IMG_ITEM) && $db->save_db_now()){

								// Page var
									$linkurl		= get_thumb_address($newname,"pt");
									$thumb_url		= get_thumb_address($newname,"dt");
									$thumb_mid_link	= get_thumb_mid_address($newname,"pm");
									$thumb_mid_url	= get_thumb_mid_address($newname,"dm");
									$imgurl			= 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$newname;
									$bookmarking	= bookmarking(($shorturl !=null?$shorturl:$thumb_mid_link),$alt);
									$open_panel		= ($settings['SET_PANEL_OPEN'] ? ' open':'');

								// Page output
									$img_posted .= '
									<div class="img_box"><a href="'.$imgurl.'" title="'.$alt.'" ><img src="'.$thumb_mid_url.'" alt="Uploaded Picture" /></a></div>
									<div class="flip">Show/Hide Links</div>
									<div class="panel'.$open_panel.'">

Er zijn 3 types: Image (Normaal) Thumb, en Small Thumb, ik zou het graag willen hebben bij Image/Normaal
 
Laatst bewerkt:
Op lijn 40 zie ik iets van extentie staan. maar als je mime hebt kan je met een switch of asosiatieve array de ext hebben
PHP:
<?php
if(!$err_get_img){
// have being experimental with this previous: $newname = rand(0,number).time().rand(0,number);
//new random name
	$newname = rand(0,number).time();
//random delete ID
	$delete_id = md5(rand(0,7).rand(0,7).time().rand(0,14));
//Image address
	$IMG_NAME = $newname.'.'.$path_info['extension'];
	$IMG_ADDRESS = $DIR_IMAGE.$IMG_NAME;
//Thumb address
	$THUMB_NAME = $newname.'.'.$THUMB_SAVE_EXT;
	$THUMB_ADDRESS = $DIR_THUMB.$THUMB_NAME;
	$THUMB_MID_ADDRESS = $DIR_THUMB_MID.$THUMB_NAME;
//Attempt to move the uploaded file to the upload folder
	if (@move_uploaded_file($file_tmp_name,$IMG_ADDRESS)) {
	// thumb
		$resizeObj = new resize($IMG_ADDRESS);
	// make thumb
		$resizeObj->resizeImage($THUMB_MID_MAX_WIDTH, $THUMB_MID_MAX_HEIGHT, $THUMB_MID_OPTION);
		$resizeObj->imageSaveQuality($THUMB_MID_QUALITY);
		$resizeObj->saveImage($THUMB_MID_ADDRESS);
	// make small thumb
		$resizeObj->resizeImage($THUMB_MAX_WIDTH, $THUMB_MAX_HEIGHT, $THUMB_OPTION);
		$resizeObj->imageSaveQuality($THUMB_QUALITY);
		$resizeObj->saveImage($THUMB_ADDRESS, $THUMB_QUALITY);
		if(file_exists($THUMB_ADDRESS) && file_exists($THUMB_MID_ADDRESS)){
			// alt text
			$alt = empty($_POST["alt"][$i]) ? $path_info['filename']:removeSymbols(input($_POST["alt"][$i]));
			if (isset($_POST['shorturl']) && $_POST['shorturl'] == 1 && $settings['SET_SHORT_URL_ON']){
				$shorturl = shorturl_url('http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$newname);
			}else{
				$shorturl = null;
			}
		// save image info to db
			$NEW_IMG_ITEM = array(	'id'		=> $newname,
									'name'		=> $file_name,
									'alt'		=> $alt,
									'added'		=> time(),
									'ext'		=> $path_info['extension'],
									'ip'		=> $_SERVER['REMOTE_ADDR'],
									'size'		=> $file_size,
									'deleteid'	=> $delete_id,
									'thumbsize' => @filesize($THUMB_MID_ADDRESS),
									'sthumbsize'=> @filesize($THUMB_ADDRESS),
									'private'	=> (isset($_POST['private'])?1:0),
									'shorturl'	=> $shorturl,
									);

			$db = new array_db($ADD_DB_IMG);
			if($db->add_row($NEW_IMG_ITEM) && $db->save_db_now()){

					// Page var
						$linkurl		= get_thumb_address($newname,"pt");
						$thumb_url		= get_thumb_address($newname,"dt");
						$thumb_mid_link	= get_thumb_mid_address($newname,"pm");
						$thumb_mid_url	= get_thumb_mid_address($newname,"dm");
						$imgurl			= 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$newname;
						$bookmarking	= bookmarking(($shorturl !=null?$shorturl:$thumb_mid_link),$alt);
						$open_panel		= ($settings['SET_PANEL_OPEN'] ? ' open':'');

					// Page output
						$img_posted .= '
						<div class="img_box"><a href="'.$imgurl.'" title="'.$alt.'" ><img src="'.$thumb_mid_url.'" alt="Uploaded Picture" /></a></div>
						<div class="flip">Show/Hide Links</div>
						<div class="panel'.$open_panel.'">';
			}
		}
	}
}
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan