Jump to content

Image upload issues


fife

Recommended Posts

OK.  I have tried to make my own image upload script which checks if the image is  bigger the 500px in height.  If it is shrinks the image down then uploads it an saves it to a database.

 

I got the upload an save to database working fine.  Once I added the check size bits it just fails with no error.  Does anybody know of any simple scripts or tuts out there that do this as Im fed up of banging my head against the wall.  Ive tried to find one myself but they dont exist it would seem!!

 

heres my code anyway just incase its fixable..

I get no error an no redirect,  I dont think its even making it to the move upload file as its not appearing on my server

 


<?php 
if(isset($_POST['submit'])){

$fileName9 = trim($_FILES['imagefile']['name']);
$tmpName = $_FILES['imagefile']['tmp_name'];
$fileType = $_FILES['imagefile']['type'];

//re name the image		
$randName = md5(rand() * time());
$fileName = $randName.$fileName9;


//where to save the image
$folder = "{$_SERVER['DOCUMENT_ROOT']}/members/images/{$members['county']}/";


//check types
$types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png');
if (in_array($fileType, $types)) {

//get original width and height 
$size = @GetImageSize($fileName); 
$width = $size[0]; 
$height = $size[1]; 

// auto adjust width of image according to predetermined height 
$new_height = 500; 
$new_width = $width * ($new_height/$height); 

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

// New image 
$image = $image_resized; 
}

// Your file handing script here
if(move_uploaded_file($tmpName , $folder.$image)) {


$qInsert = mysql_query("UPDATE `members` 
SET profilePic = '$image' WHERE userID = '".$members['userID']."'") or die (mysql_error());
} 

if ($qInsert){
$url = "/members/clubs/image.php?pic=$image";        
header("Location: $url");  
}


}


 ?>
        
        
   
      <form action="" method="post" enctype="multipart/form-data" name="photo" id="photo">
      	<input name="imagefile" type="file">
        <input name="submit" type="submit" id="submit">
      </form>

 

 

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.