0

Hi aLL

I have got problen in uploading photo in profile.

when i checked coding i found !

here is where i found this sign

// UPLOAD PHOTO
if( $task == "upload" )
{
$user->user_photo_upload("photo");
$is_error = $user->is_error;
if( !$is_error )


// UPLOAD PHOTO
if( $task == "upload" )
{
$user->user_photo_upload("photo");
$is_error = $user->is_error;
if( !$is_error )

If above is correct please help me and tell me where is any thing wrong

Below is code of full page

<?php

/* $Id: user_editprofile_photo.php 130 2009-03-21 23:36:57Z john $ */

$page = "user_editprofile_photo";
include "header.php";

$task = ( isset($_POST['task']) ? $_POST['task'] : NULL );

// CHECK FOR ADMIN ALLOWANCE OF PHOTO
if( !$user->level_info['level_photo_allow'] )
{
  header("Location: user_home.php");
  exit();
}

// SET ERROR VARIABLES
$is_error = 0;

// DELETE PHOTO
if( $task == "remove" )
{
  $user->user_photo_delete();
  $user->user_lastupdate();
  exit();
}


// UPLOAD PHOTO
if( $task == "upload" )
{
  $user->user_photo_upload("photo");
  $is_error = $user->is_error;
  if( !$is_error )
  {
    // SAVE LAST UPDATE DATE
    $user->user_lastupdate(); 
    
    // DETERMINE SIZE OF THUMBNAIL TO SHOW IN ACTION
    $photo_width = $misc->photo_size($user->user_photo(), "100", "100", "w");
    $photo_height = $misc->photo_size($user->user_photo(), "100", "100", "h");
    
    // INSERT ACTION
    $action_media = Array(Array('media_link'=>$url->url_create('profile', $user->user_info['user_username']), 'media_path'=>$user->user_photo(), 'media_width'=>$photo_width, 'media_height'=>$photo_height));
    $actions->actions_add($user, "editphoto", Array($user->user_info['user_username'], $user->user_displayname), $action_media, 999999999, TRUE, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
  }
}

// GET TABS TO DISPLAY ON TOP MENU
$field = new se_field("profile", $user->profile_info);
$field->cat_list(0, 0, 0, "profilecat_id='{$user->user_info['user_profilecat_id']}'");
$cat_array = $field->subcats;


// ASSIGN VARIABLES AND INCLUDE FOOTER
$smarty->assign('is_error', $is_error);
$smarty->assign('cats', $cat_array);
include "footer.php";
?>
3
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by jibon57
0

What is the error message you get when it fails?
If there is no error on the page - displayed inline, do you have an error message in the server error log?
There is no problem with the ! mark in the code - it simply means - NOT. So, translated in human language 'If there is no value stored as error message do...'

What bothers me is this line in your code

$task = ( isset($_POST['task']) ? $_POST['task'] : NULL );

I suppose you check here for empty post, but you did it wrong. So, I suppose error message will show where the error actually is.

0

no error when i slect file from brows it starts loading then refresh the same page

No error No msg nothing
onlt i takes refresh.

0

Below are to codes 1st is to upload image for article it works

second one is for profile image.

<?
$page = "user_article_edit";
include "header.php";
if($user->level_info[level_article_allow] == 0) { header("Location: user_home.php"); exit(); }
if(isset($_POST['article_id'])) { $article_id = $_POST['article_id']; } elseif(isset($_GET['article_id'])) { $article_id = $_GET['article_id']; } else { $article_id = 0; }
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
if(isset($_POST['justadded'])) { $justadded = $_POST['justadded']; } elseif(isset($_GET['justadded'])) { $justadded = $_GET['justadded']; } else { $justadded = ""; }


// INITIALIZE ARTICLE OBJECT
$article = new rc_article($user->user_info[user_id], $article_id);
$rc_tag = new rc_articletag();

if($article->article_exists == 0) { header("Location: user_article.php"); exit(); }
if($article->article_info[article_user_id] != $user->user_info[user_id]) { header("Location: user_article.php"); exit(); }


// SET ERROR VARIABLES
$is_error = 0;
$result = 0;
$error_message = "";

// GET PRIVACY SETTINGS
$level_article_privacy = unserialize($user->level_info[level_article_privacy]);
rsort($level_article_privacy);
$level_article_comments = unserialize($user->level_info[level_article_comments]);
rsort($level_article_comments);

// CHECK FOR ADMIN ALLOWANCE OF PHOTO
if($article->articleowner_level_info[level_article_photo] == 0 & ($task == "remove" | $task == "upload")) { $task = "main"; }


// DELETE PHOTO
if($task == "remove") { $article->article_photo_delete(); $article->article_lastupdate(); }

[B]// UPLOAD PHOTO
if($task == "upload") {
  $article->article_photo_upload("photo");
  $is_error = $article->is_error;
  $error_message = $article->error_message;
  if($is_error == 0) { $user->user_photo_lastupdate(); }
}[/B]



if($task == "dosave") {
  // GET BASIC ARTICLE INFO
  $article_title = censor($_POST['article_title']);
  $article_body = censor($_POST['article_body']);

  $articlecat_id = $_POST['articlecat_id'];
  $subarticlecat_id = $_POST['subarticlecat_id'];
  $article_draft = $article->article_info[article_draft];
  $article_date_start = $article->article_info[article_date_start];
  $article_search = $_POST['article_search'];
  $article_privacy = $_POST['article_privacy'];
  $article_comments = $_POST['article_comments'];
  $article_tags = rc_toolkit::get_request('article_tags');

  // CHECK TO MAKE SURE TITLE HAS BEEN ENTERED
  if(str_replace(" ", "", $article_title) == "") {
    $is_error = 1;
    $error_message = 11151408;
  }

  // MAKE SURE SUBMITTED PRIVACY OPTIONS ARE ALLOWED, IF NOT, SET TO EVERYONE
  if(!in_array($article_privacy, $level_article_privacy)) { $article_privacy = $level_article_privacy[0]; }
  if(!in_array($article_comments, $level_article_comments)) { $article_comments = $level_article_comments[0]; }

  // CHECK THAT SEARCH IS NOT BLANK
  if($article->articleowner_level_info[level_article_search] == 0) { $article_search = 1; }

  //$article_approved = ($user->level_info[level_article_approved] == 0) ? 1 : 0;

  // IF NO ERROR, SAVE ARTICLE
  if($is_error == 0) {
    if($subarticlecat_id != 0) { $new_articlecat_id = $subarticlecat_id; } else { $new_articlecat_id = $articlecat_id; }

    if (isset($_POST['publish'])) {
      $article_draft = 0;
      $article_date_start = time();

      if ($article->article_info[article_approved] > 0) {
	      $article_title_short = $article_title;
	      if(strlen($article_title_short) > 100) { $article_title_short = substr($article_title_short, 0, 97); $article_title_short .= "..."; }
	      $actions->actions_add($user, "newarticle", Array('[username]', '[id]', '[title]', '[publish_date]'), Array($user->user_info[user_username], $article_id, $article_title_short, date("F j, Y, g:i a",$article_date_start)));
      }
      
    }    
    
    // UPDATE ARTICLE
    $article_slug = $article->generate_slug($article_title);
    
    $database->database_query("UPDATE se_articles SET article_slug='$article_slug', article_title='$article_title', article_articlecat_id='$new_articlecat_id', article_body='$article_body', article_date_start='$article_date_start', article_draft='$article_draft', article_search='$article_search', article_privacy='$article_privacy', article_comments='$article_comments'  WHERE article_id='".$article->article_info[article_id]."'");
    $database->database_query("UPDATE se_articlealbums SET articlealbum_privacy='$article_privacy', articlealbum_comments='$article_comments', articlealbum_search='$article_search' WHERE articlealbum_article_id='".$article->article_info[article_id]."'");
    $rc_tag->update_object_tags($article_id, $article_tags);
    
    // RESET RESULTS
    $article->article_info = $database->database_fetch_assoc($database->database_query("SELECT * FROM se_articles WHERE article_id='".$article->article_info[article_id]."'"));


    
    // SET RESULT MESSAGE
    $result = 1;

    $article->article_lastupdate();
  }




}
else {
  $article_title = $article->article_info[article_title];
 
  $article_body = $article->article_info[article_body];
  $article_date_start = $article->article_info[article_date_start];
  $article_tags = join(', ',$rc_tag->get_object_tags($article_id));
  $article_inviteonly = $article->article_info[article_inviteonly];
  $article_search = $article->article_info[article_search];
  $article_privacy = $article->article_info[article_privacy];
  $article_comments = $article->article_info[article_comments];
  $article_draft = $article->article_info[article_draft] ? 1 : 0;
  if($article->article_info[article_articlecat_id] == 0) {
    $articlecat_id = 0;
    $subarticlecat_id = 0;
  } else {
    $articlecat = $database->database_fetch_assoc($database->database_query("SELECT articlecat_id, articlecat_dependency FROM se_articlecats WHERE articlecat_id='".$article->article_info[article_articlecat_id]."'"));
    if($articlecat[articlecat_dependency] == 0) {
      $articlecat_id = $articlecat[articlecat_id];
      $subarticlecat_id = "0";
    } else {
      $parentarticlecat = $database->database_fetch_assoc($database->database_query("SELECT articlecat_id FROM se_articlecats WHERE articlecat_id='$articlecat[articlecat_dependency]'"));
      $articlecat_id = $parentarticlecat[articlecat_id];
      $subarticlecat_id = $articlecat[articlecat_id];
    }
  }
}





// GET ARTICLE CATEGORIES
$categories_array = Array();
$categories_query = $database->database_query("SELECT * FROM se_articlecats WHERE articlecat_dependency='0' ORDER BY articlecat_id");
while($category = $database->database_fetch_assoc($categories_query)) {
  // GET DEPENDENT ARTICLE CATS
  $dep_categories_query = $database->database_query("SELECT * FROM se_articlecats WHERE articlecat_dependency='$category[articlecat_id]' ORDER BY articlecat_id");
  $dep_articlecat_array = Array();
  while($dep_category = $database->database_fetch_assoc($dep_categories_query)) {
    $dep_articlecat_array[] = Array('subarticlecat_id' => $dep_category[articlecat_id],
					'subarticlecat_title' => $dep_category[articlecat_title]);
  }

  $categories_array[] = Array('articlecat_id' => $category[articlecat_id],
			       'articlecat_title' => $category[articlecat_title],
			       'subcats' => $dep_articlecat_array);
}






// GET PREVIOUS PRIVACY SETTINGS
for($c=0;$c<count($level_article_privacy);$c++) {
  if(user_privacy_levels($level_article_privacy[$c]) != "") {
    SE_Language::_preload(user_privacy_levels($level_article_privacy[$c]));
    $privacy_options[$level_article_privacy[$c]] = user_privacy_levels($level_article_privacy[$c]);
  }
}

for($c=0;$c<count($level_article_comments);$c++) {
  if(user_privacy_levels($level_article_comments[$c]) != "") {
    SE_Language::_preload(user_privacy_levels($level_article_comments[$c]));
    $comment_options[$level_article_comments[$c]] = user_privacy_levels($level_article_comments[$c]);
  }
}

//rc_toolkit::debug($article);


// ASSIGN VARIABLES AND SHOW USER EDIT ARTICLE PAGE
$smarty->assign('result', $result);
$smarty->assign('is_error', $is_error);
$smarty->assign('justadded', $justadded);
$smarty->assign('error_message', $error_message);
$smarty->assign('article', $article);
$smarty->assign('privacy_options', $privacy_options);
$smarty->assign('comment_options', $comment_options);
$smarty->assign('cats', $categories_array);
$smarty->assign('article_title', $article_title);
$smarty->assign('article_body', str_replace("\r\n", "", html_entity_decode($article_body)));
$smarty->assign('article_date_start', $article_date_start);
$smarty->assign('article_draft', $article_draft);
$smarty->assign('articlecat_id', $articlecat_id);
$smarty->assign('subarticlecat_id', $subarticlecat_id);
$smarty->assign('article_tags', $article_tags);
$smarty->assign('article_search', $article_search);
$smarty->assign('article_privacy', $article_privacy);
$smarty->assign('article_comments', $article_comments);
include "footer.php";
?>

second one which does not work

<?php

/* $Id: user_editprofile_photo.php 130 2009-03-21 23:36:57Z john $ */

$page = "user_editprofile_photo";
include "header.php";

$task = ( isset($_POST['task']) ? $_POST['task'] : NULL );

// CHECK FOR ADMIN ALLOWANCE OF PHOTO
if( !$user->level_info['level_photo_allow'] )
{
  header("Location: user_home.php");
  exit();
}

// SET ERROR VARIABLES
$is_error = 0;

// DELETE PHOTO
if( $task == "remove" )
{
  $user->user_photo_delete();
  $user->user_lastupdate();
  exit();
}


[B]// UPLOAD PHOTO
if( $task == "upload" )
{
  $user->user_photo_upload("photo");
  $is_error = $user->is_error;
  if( !$is_error )[/B]
  {
    // SAVE LAST UPDATE DATE
    $user->user_lastupdate(); 
    
    // DETERMINE SIZE OF THUMBNAIL TO SHOW IN ACTION
    $photo_width = $misc->photo_size($user->user_photo(), "100", "100", "w");
    $photo_height = $misc->photo_size($user->user_photo(), "100", "100", "h");
    
    // INSERT ACTION
    $action_media = Array(Array('media_link'=>$url->url_create('profile', $user->user_info['user_username']), 'media_path'=>$user->user_photo(), 'media_width'=>$photo_width, 'media_height'=>$photo_height));
    $actions->actions_add($user, "editphoto", Array($user->user_info['user_username'], $user->user_displayname), $action_media, 999999999, TRUE, "user", $user->user_info['user_id'], $user->user_info['user_privacy']);
  }
}

// GET TABS TO DISPLAY ON TOP MENU
$field = new se_field("profile", $user->profile_info);
$field->cat_list(0, 0, 0, "profilecat_id='{$user->user_info['user_profilecat_id']}'");
$cat_array = $field->subcats;


// ASSIGN VARIABLES AND INCLUDE FOOTER
$smarty->assign('is_error', $is_error);
$smarty->assign('cats', $cat_array);
include "footer.php";
?>
0

wherever I trying to upload my photo it's show this kind of message.

"Warning: copy(images/101325241283607762.jpg): failed to open stream: Permission denied in /www/zxq.net/j/k/k/jkkniu/htdocs/log in/upload3.php on line 71"

Can any one help me. i using this php

<?php
//define a maxim size for the uploaded images in Kb
 define ("MAX_SIZE","3000"); 


      $rollno = $_SESSION['rollno'];
      $batch =$_SESSION['batch'];


      $query = "SELECT * FROM $batch WHERE rollno = '$rollno'";

      $result = mysql_query($query) or die('Error : ' . mysql_error());
      $count=mysql_num_rows($result);
      $row = mysql_fetch_array($result);

      $owner = $row['rollno'];

//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
//and it will be changed to 1 if an errro occures.  
//If the error occures the file will not be uploaded.
 $errors=0;
//checks if the form has been submitted
 if(isset($_POST['Submit'])) 
 {
    //reads the name of the file the user submitted for uploading
    $image=$_FILES['image']['name'];
    //if it is not empty
    if ($image) 
    {
    //get the original name of the file from the clients machine
        $filename = stripslashes($_FILES['image']['name']);
    //get the extension of the file in a lower case format
        $extension = getExtension($filename);
        $extension = strtolower($extension);
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
    //otherwise we will do more tests
 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
        {
        //print error message
            echo '<h1>Unknown extension!</h1>';
            $errors=1;
        }
        else
        {
//get the size of the image in bytes
 //$_FILES['image']['tmp_name'] is the temporary filename of the file
 //in which the uploaded file was stored on the server
 $size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
    echo '<h1>You have exceeded the size limit! Please try with another.</h1>';
    $errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$username.$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
{

        echo '<h1>Copy unsuccessfull!</h1>';  die(mysql_error());



    $errors=1;
}}}}

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors) 
 {

     $photo= $row['photo'];
      echo $photo;
      $delete= unlink($photo);
      echo $delete;

      $result = mysql_query("UPDATE $batch SET photo='$rollno' WHERE rollno='$owner'") or die(mysql_error($result));

      $photo=$_SESSION['photo'];

    echo "<h1>File Uploaded Successfully! </h1>" or die(mysql_error());


 }

 ?>

 <form name="newad" method="post" enctype="multipart/form-data"  action="">
 <table>
    <tr><td><input type="file" name="image"></td></tr>
    <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
 </table>    
 </form>

Edited by Nick Evan: Fixed formatting

0

wherever I trying to upload my photo it's show this kind of message.

"Warning: copy(images/101325241283607762.jpg): failed to open stream: Permission denied in /www/zxq.net/j/k/k/jkkniu/htdocs/log in/upload3.php on line 71"

Can any one help me. i using this php

<?php
//define a maxim size for the uploaded images in Kb
 define ("MAX_SIZE","3000"); 


      $rollno = $_SESSION['rollno'];
      $batch =$_SESSION['batch'];


      $query = "SELECT * FROM $batch WHERE rollno = '$rollno'";

      $result = mysql_query($query) or die('Error : ' . mysql_error());
      $count=mysql_num_rows($result);
      $row = mysql_fetch_array($result);

      $owner = $row['rollno'];

//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
//and it will be changed to 1 if an errro occures.  
//If the error occures the file will not be uploaded.
 $errors=0;
//checks if the form has been submitted
 if(isset($_POST['Submit'])) 
 {
    //reads the name of the file the user submitted for uploading
    $image=$_FILES['image']['name'];
    //if it is not empty
    if ($image) 
    {
    //get the original name of the file from the clients machine
        $filename = stripslashes($_FILES['image']['name']);
    //get the extension of the file in a lower case format
        $extension = getExtension($filename);
        $extension = strtolower($extension);
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
    //otherwise we will do more tests
 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
        {
        //print error message
            echo '<h1>Unknown extension!</h1>';
            $errors=1;
        }
        else
        {
//get the size of the image in bytes
 //$_FILES['image']['tmp_name'] is the temporary filename of the file
 //in which the uploaded file was stored on the server
 $size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
    echo '<h1>You have exceeded the size limit! Please try with another.</h1>';
    $errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$username.$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
{

        echo '<h1>Copy unsuccessfull!</h1>';  die(mysql_error());



    $errors=1;
}}}}

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors) 
 {

     $photo= $row['photo'];
      echo $photo;
      $delete= unlink($photo);
      echo $delete;

      $result = mysql_query("UPDATE $batch SET photo='$rollno' WHERE rollno='$owner'") or die(mysql_error($result));

      $photo=$_SESSION['photo'];

    echo "<h1>File Uploaded Successfully! </h1>" or die(mysql_error());


 }

 ?>

 <form name="newad" method="post" enctype="multipart/form-data"  action="">
 <table>
    <tr><td><input type="file" name="image"></td></tr>
    <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
 </table>    
 </form>

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.