Re: upload image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
It looks like:

function uploadImage($inputName, $uploadDir)
{
	$image     = $_FILES[$inputName];
	$imagePath = '';
	$thumbnailPath = '';
	
	// if a file is given
	if (trim($image['tmp_name']) != '') {
		$ext = substr(strrchr($image['name'], "."), 1); 

		// generate a random new file name to avoid name conflict
		// then save the image under the new file name
		$imagePath = md5(rand() * time()) . ".$ext";
		$result    = move_uploaded_file($image['tmp_name'], $uploadDir .
$imagePath);
			
		if ($result) {
			// create thumbnail
			$thumbnailPath =  md5(rand() * time()) . ".$ext";
			$result = createThumbnail($uploadDir . $imagePath, $uploadDir .
'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH);
			
			// create thumbnail failed, delete the image
			if (!$result) {
				unlink($uploadDir . $imagePath);
				$imagePath = $thumbnailPath = '';
			} else {
				$thumbnailPath = $result;
			}	
		} else {
			// the image cannot be uploaded
			$imagePath = $thumbnailPath = '';
		}
		
	}

	
	return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}


Mourad Boulahboub wrote:
> 
> Hi sonja,
> 
> 
> 
> Sonja schrieb am 24.08.2006 09:38:
>> Hi,
>> 
>> I have problems with uploading image, here is the code
>> 
>> if(isset($_POST['txtTitle']))
>> {
>> 	$albumId   = $_POST['cboAlbum'];
>> 	$imgTitle  = $_POST['txtTitle'];
>> 	$imgDesc   = $_POST['mtxDesc'];
>> 
>> 	$images    = uploadImage('fleImage', GALLERY_IMG_DIR);
> 
> how does the function uploadImage looks like?
> 
> 
>> 	if ($images['image'] == '' && $images['thumbnail'] == '') {
>> 		echo "Error uploading file";
>> 		exit;
>> 	}
> 
> the error comes from this if-clause that is depending from the function
> above.
> 
> regards
> Mourad
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/upload-image-tf2157181.html#a5961434
Sent from the PHP - General forum at Nabble.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux