Jump to content

Please can someone help uploading files ?


Accurax

Recommended Posts

Im having serious trouble with this, and i really really need some advise.

 

Heres my code as it stands:

 

<?php
session_start();
include("password.inc");
include("function.inc");

if ( $_SESSION['login'] != "true" )
{
	header("location: ../Signup/registration.php");
}
else
{
	$connection=mysql_connect($host, $user, $passwd)
	or die ("Could not connect !");
	$db = mysql_select_db($database, $connection)
	or die ("Could not connect to Database");


//--------------------------------------------

   
   if (($_FILES['filename']['type']!="image/jpeg") && ($_FILES['filename']['type']!="image/pjpeg") && ($_FILES['filename']['type']!="image/gif")) {
      
      echo "Sorry you must upload only files of the type .jpg .jpeg or .gif, Click <a href='../picturemanager.php'>Here</a> to try again";
   
   } else {

      $query = "SELECT picture1 FROM pictures WHERE user_name='$username'";
      $exist = mysql_query($query) or die ("could not Select Picture.");

      preg_match('/\.\w{3,4}$/', $_FILES['filename']['name'], $matches);
      $new_filename = $_SESSION['username']."1".$matches[0];

      $filepath = "member_pics/full_size/".$new_filename;


if (file_exists($filepath)) {
          unlink("member_pics/full_size/".$new_filename);
	  $username = $_SESSION['username'];

      }
  
      $source = "member_pics/full_size/";
      move_uploaded_file($_FILES['filename']['tmp_name'], "../../$source".$new_filename); // this line is for local host
         /*"../xxx/xxx/".$_FILES['filename']['name']);*/ //this line is for remote server


      $query = "UPDATE pictures SET picture1 = '$filepath' WHERE user_name='{$_SESSION['username']}'";
      $result = mysql_query($query) or die ("could not add picture.");
   }

//-------------------------------------****

      $query = "SELECT thmb_1 FROM pictures WHERE user_name='$username'";
      $exist = mysql_query($query) or die ("could not Select Picture.");

      preg_match('/\.\w{3,4}$/', $_FILES['filename']['name'], $matches);
      $thmb_filename = $_SESSION['username']."_thmb_1".$matches[0];

      $thmb_filepath = "member_pics/thumbnails/".$thmb_filename;
  	


if (file_exists($thmb_filepath)) {
          unlink("member_pics/thumbnails/".$thmb_filename);
	  $username = $_SESSION['username'];

      }
//try to create thumbnail

// Get original width and height
$truepath = "../../".$thmb_filepath;
$image = imagecreatefromjpeg($truepath);


if ($image === false) { 
die ('Unable to open image'); 
}

$width = imagesx($image);
$height = imagesy($image);

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

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

//move the thumbnail	  
      $source = "member_pics/thumbnails/";
      move_uploaded_file($image_resized, $thmb_filepath); // this line is for local host



      $query = "UPDATE pictures SET thmb_1 = '$thmb_filepath' WHERE user_name='{$_SESSION['username']}'";
      $result = mysql_query($query) or die ("could not add picture.");
   }

?>

 

The first section works correctly.

 

The problem is witht he handling of the thumbnail ...... the script adds the correct path for the thmb to my database, however, i cant get it to actually upload the reduced size image to the thumbnail directory.

 

It feels like im really close..... but i could really use some help please.

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/40196-please-can-someone-help-uploading-files/
Share on other sites

Will it upload the original image?

 

If it does, then I expect it is permissions on the thumbs directory. Set them them to read/write, I expect they are 'read' only at the moment.

 

Any half decent ftp program will let you do this.

 

monk.e.boy

Yes it uploads the first file fine.

 

But there is no problem with file permissions ............ im really getting upset at my inability to get this to work ... i really need help ive spent 6 hours messing with this now and have achieved the square root of bugger all.

*Accurax bangs head repeatedly against desk

//move the thumbnail	  
      $source = "member_pics/thumbnails/";
      move_uploaded_file($image_resized, $thmb_filepath); // this line is for local host

 

this bit is wrong. You don't want to move_uploaded_file, you want to save your image resource, do imagejpeg($image_resized, '/my/long/path/thumb.jpg');

 

http://sniptools.com/tutorials/generating-jpggifpng-thumbnails-in-php-using-imagegif-imagejpeg-imagepng

 

I am google king.

 

;D ;D ;D ;D

 

monk.e.boy

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.