Jump to content

Image Upload


phpretard

Recommended Posts

This is the script I'm using to upload images.  Is there something I can add to resize the image proportionaly so that is fits on the page where it is later echoed? 

 

or

 

Can I set a max width / height when displayed?

 

 

function findexts ($filename) 
{ 
$filename = strtolower($filename) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n]; 
return $exts; 
} 

$ext = findexts ($_FILES['uploaded']['name']) ; 

$ran = rand (111111, 999999). $company ;

$ran2 = $ran.".";

$target = "pages/secure/partners/img/";

$target = $target . $ran2.$ext;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{

mysql_query("INSERT INTO partners (id, company, url, uploaded, blurb ) 
VALUES ('', '$company', '$url', '$target', '$blurb')");

$success="<center><font color=red size=2>Upload Successful!</font><br><br></center>";

}

Link to comment
Share on other sites

Use the GD PHP Extension here is a simple script to resize an image

 

 

<?php

// Load image
$image = open_image('flower.jpg');
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height
$new_width = 150;
$new_height = 100;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();

?>

Link to comment
Share on other sites

I am really trying to keep this as simple as possible.

 

I have many different size images in different formats in a file and just want to display them with a max height and width.

 

I tried CSS well... IE is IE (works great in FF).

 

Is there a simple way?

 

Link to comment
Share on other sites

Give width as fixed instead of percentage in CSS. Do not specify height, it will adjust automatically.

 

However i would advice using the script given by Loldongs.

 

This will save you upload time, disk space and page rendering time.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.