Upload error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Upload error

Post by my_raj_raj2 »

Hi,

I used class upload.inc Version 0.17. For upload an image.

When I upload an image I received error in the processing.



I don't know why it is appear?

Help me.

Thanking You.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: Upload error

Post by feyd »

my_raj_raj2 wrote:Help me.
Can't. Nothing you have posted tells us much. The only thing I know is you're using an upload handling class. That's pretty vague.
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Post by my_raj_raj2 »

Hi

Thanks for ur reply.


I used this class for upload but I have more doubts in this class.

some problem in converting image into jpeg format.

I download the class from

http://www.verot.net/php_class_upload_overview.htm

But I have More doubts in it.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Please can you construct a proper question. English may not be your first language, but you really need to help us to help you.
  • 1) Outline the problem you are having
  • 2) Show us your code
  • 3) Tell us what the error is you are recieving
Until you have done this, nobody can help you.
my_raj_raj2
Forum Commoner
Posts: 28
Joined: Mon Mar 20, 2006 8:06 am
Location: India

Post by my_raj_raj2 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is the  coding for upload an image,

Code: Select all

function uploadFeaturedPhoto()
{ 
	global $db, $page, $config, $debug;
	
	// check user
  if(!validUser())
  {
    delayRedirect("index.php",5,"You don't have access to this part of site. Please log-in.");
  }

  // check if user have one image
  $sql = 'SELECT reps.photo_id, images.filename FROM reps'
       . ' LEFT JOIN images ON reps.photo_id = images.id'
       . ' WHERE reps.id = ' . $_SESSION['id'];
  $oldImage = $db->fetchArray($db->query($sql));
  if ($oldImage['filename']) 
  {
  	$sql = 'DELETE FROM images WHERE id = ' . $oldImage['photo_id'] . ' LIMIT 1';
  	$db->query($sql);
  	@unlink($config['upload_dir'] . $oldImage['filename']);
  }
  
  // upload new image
  $uploader = new upload($_FILES["photo"]);
  if ($uploader->uploaded)
  {
    do 
    {
      $file_new_name = sprintf("reps%d_%s",$_SESSION['id'],(string) uniqid(5));
    } while(file_exists($config['upload_dir'].$file_new_name.'jpg'));
    $uploader->file_new_name_body   = $file_new_name; 
    $uploader->image_resize         = true;
    $uploader->image_convert        = 'jpg';
    $uploader->image_x              = 100;
	$uploader->image_y              = 100;
    $uploader->image_ratio_y        = false;
    $uploader->image_ratio_x        = false;
    $uploader->process($config['upload_dir']); $a=1;
    if($uploader->processed)
    {
      // insert image into db;
      // database operations
      $uploaded['filename'] = $uploader->file_dst_name;
      $sql = 'INSERT INTO images SET'
           . ' id = 0,'
           . ' filename = \'' . $uploaded['filename'] . '\'';
      $db->query($sql);
      $id = null;
      $debug[] = $config['upload_dir'] . $uploaded['filename'];
      if ($db->affectedRows() == 1)
      {
        // the last id
        $id = $db->insertId();
      }
      else
      {
        // clean the photo
        @unlink($config['upload_dir'] . $uploaded['filename']);
        unset($uploaded);
      }
      
      if ($id) 
      {
      	$sql = 'UPDATE reps SET photo_id = ' . $id . ' WHERE id = ' . $_SESSION['id'] . ' LIMIT 1';
      	$db->query($sql);
      	 doRedirect("index.php?mod=reps-home");
       }
      else 
      {
      	delayRedirect("index.php?mpd=reps-home",5,
		'<div class="error_box">Error, photo wasn\'t updated</div>');  
        }
    }
  }
  else 
  {
  	doRedirect("index.php?mod=reps-home");
   }
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply