Jump to content
Killersites Community

phpNOvice

Member
  • Content Count

    44
  • Joined

  • Last visited

Community Reputation

0 Neutral

About phpNOvice

  • Rank
    Member
  1. phpNOvice

    Renaming Uploaded Photo

    this has been solved
  2. phpNOvice

    Renaming Uploaded Photo

    Hello killers, I have manage to create codes that could upload a image that is purposely to serve as profile picture of a certain student. My problem is how to rename it to aN AUTO COLLATE UNIQUE ID NUMBER so that i can display it specifically to a certain student account which bears the unique id number. The variable is $student_id. <?php session_start(); $session_id = $_SESSION['user_id']; if($session_id == null){ header("location:Student_Edit.php"); die(); } include 'Connect.php'; $flag = ""; $result = mysql_query("SELECT * FROM student_information where student_id='{$_SESSION['user_id']}'",$link_id);; $data = mysql_fetch_array($result); ?> <div class="style3" > <?php $uploadpath = 'upload/'; $max_size = 2000; $alwidth = 900; $alheight = 800; $allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png','psd'); if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) { $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); $sepext = explode('.', strtolower($_FILES['fileup']['name'])); $type = end($sepext); list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); $err = ''; if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.'; if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.'; if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight; if($err == '') { if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) { echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:'; echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>'; echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB'; if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height; echo '<br/><br/>Image address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>'; } else echo '<b>Unable to upload the file.</b>'; } else echo $err; } ?> Please modify my codes to rename the uploaded file to the student id of the student who is uploading it.
  3. Hello Ben, i have solved the flag part but still the problem of uploading image is there even i have followed your advise in enctype="multipart/form-data" which i have missed also last time. I got brand new codes now and best thing is i got WARNING displayed. Kindly help me this out. <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); session_start(); $session_id = $_SESSION['user_id']; if($session_id == null){ header("location:Student_Edit.php"); die(); } include 'Connect.php'; $flag = ""; $student_id = $_POST['student_id']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $gender = $_POST['gender']; $date_of_birth = date("Y-m-d",strtotime($_POST['date_of_birth'])); $contact_no = $_POST['contact_no']; $grade = $_POST['grade']; $section = $_POST['section']; $LRN = $_POST['LRN']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $address = $_POST['address']; $description = $_POST['description']; $imagename = ""; $query = "UPDATE student_information SET first_name='$first_name',last_name='$last_name',"; $query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',"; $query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description'"; $query .= " WHERE student_id='{$_SESSION['user_id']}'"; $result = mysql_query($query, $link_id); if(mysql_error() != null){ die(mysql_error()); } if($_FILES['image']['name'] != ""){ $filename = $_FILES['image']['name']; $ext = strrchr($filename,"."); $imagename = $student_id; $imagename .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['image']['size']; if($size > 0 && $size < 1000000){ $archive_dir = "images/".$student_id; $userfile_tmp_name = $_FILES['image']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, $archive_dir)){ mysql_query("update student_information set image='$imagename' where student_id='{$_SESSION['user_id']}'", $link_id); $flag = "success"; if(mysql_error()!=null){ die(mysql_error()); } } else{ if(file_exists('images/' . $imagename)) { unlink('images/' . $imagename); } rollbackData(); } } else{ if(file_exists('images/' . $imagename)) { unlink('images/' . $imagename); } rollbackData(); die("You can upload image of 1 MB size only. Please, try again."); } } else{ if(file_exists('images/' . $imagename)) { unlink('images/' . $imagename); } rollbackData(); die("You can upload images of .jpg, .jpeg, .gif extensions only. Please, try again. "); } } if($result){ $flag = "success"; } else{ $flag = "error"; } header("location:Student_Edit.php?flag=$flag&student_id='{$_SESSION['user_id']}'"); ?> and these are the 3 warnings displayed except for being deprecated maybe you can figure this out. Warning: move_uploaded_file(images/<br /> <b>Notice</b>: Undefined variable: student_id in <b>C:\xampp\htdocs\a\Student_Edit.php</b> on line <b>112</b><br /> : failed to open stream: Invalid argument inC:\xampp\htdocs\a\Student_Edit_Handler.php on line 45 Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php87E3.tmp' to 'images/<br /> <b>Notice</b>: Undefined variable: student_id in <b>C:\xampp\htdocs\a\Student_Edit.php</b> on line <b>112</b><br /> ;' in C:\xampp\htdocs\a\Student_Edit_Handler.php on line 45 Fatal error: Call to undefined function rollbackData() in C:\xampp\htdocs\a\Student_Edit_Handler.php on line 56 Please advise
  4. Hi there, i have recieved this notice Warning: Header may not contain more than a single header, new line detected in C:\xampp\htdocs\a\Student_Edit_Handler.php on line 53 and these are my codes. Kindly help me to fix this. <?php session_start(); $session_id = $_SESSION['user_id']; if($session_id == null){ header("location:Student_Edit.php"); die(); } include 'Connect.php'; $flag = "success"; function rollbackData(){ mysql_query(" ROLLBACK "); global $flag; $flag = "error"; if(mysql_error() != null){ die(mysql_error()); } } $student_id = $_POST['student_id']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $gender = $_POST['gender']; $date_of_birth = date("Y-m-d",strtotime($_POST['date_of_birth'])); $contact_no = $_POST['contact_no']; $grade = $_POST['grade']; $section = $_POST['section']; $LRN = $_POST['LRN']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $address = $_POST['address']; $description = $_POST['description']; $imagename = ""; $flag= ""; mysql_query("SET AUTOCOMMIT = 0 "); if(mysql_error() != null){ die(mysql_error()); } $query = "UPDATE student_information SET first_name='$first_name',last_name='$last_name',"; $query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',"; $query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description'"; $query .= " WHERE student_id='{$_SESSION['user_id']}'"; $result = mysql_query($query, $link_id); if(mysql_error() != null){ die(mysql_error()); } if($result) { $flag = "success"; } else { $flag = "error"; } header("location:Student_Edit.php?flag=$flag&student_id=student_id=$student_id"); ?> Please advise
  5. These are my codes in the html <tr class="stylesmall"> <td>Update Learner Image: </td> <td colspan="3"><input type="file" name="image"> <span class="style3"> <span class="stylesmall">jpg or gif file only</span></span></td> </tr> <tr> <td colspan="4"><span class="stylered style6"><span class="style3">*</span> <em>fields are compulsory</em></span></td> </tr> <tr> <td colspan="4" align="center"><input name="update" type="submit" id="update" value="Update"> i read the link you gave me and tried to modify some codes but then it end up same error.
  6. i have writen flags on theStudent_Edit.php. <?php if(!empty($_GET['flag']) && $_GET['flag'] == "success") { ?> <span class="stylered style1"><span class="style5">Learner Information updated successfully.</span></span> <?php } else if(!empty($_GET['flag']) && $_GET['flag'] == "error") { ?> <span class="stylered style3 style5"><span class="style1">Error while updating Learner Information. Please try again</span></span> <?php } ?> </td> the specific error im getting is the flag=error which is "Error while updating Learner Information. Please try again." The reason im pasting almost the whole codes.
  7. Hi Ben, i got new codes now that uploads the image of registered student with unique student_id. it is called Student_Edit_handler. This was in response to the idea you suggested. $student_id = $_POST['student_id']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $gender = $_POST['gender']; $date_of_birth = date("Y-m-d",strtotime($_POST['date_of_birth'])); $contact_no = $_POST['contact_no']; $grade = $_POST['grade']; $section = $_POST['section']; $LRN = $_POST['LRN']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $address = $_POST['address']; $description = $_POST['description']; $imagename = ""; $flag= ""; mysql_query("SET AUTOCOMMIT = 0 "); if(mysql_error() != null){ die(mysql_error()); } $query = "UPDATE student_information SET first_name='$first_name',last_name='$last_name',"; $query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',"; $query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description'"; $query .= " WHERE student_id='{$_SESSION['user_id']}'"; $result = mysql_query($query, $link_id); if(mysql_error() != null){ die(mysql_error()); } /* This block shows the start codes for the upload of the Learner's image */ if($_FILES['image']['name'] != ""){ $filename = $_FILES['image']['name']; $ext = strrchr($filename,"."); $imagename = $student_id; $imagename .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['image']['size']; if($size > 0 && $size < 1000000){ $archive_dir = "images"; $userfile_tmp_name = $_FILES['image']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, $archive_dir .'/'. $student_id .'_'. $imagename .'.'. $ext)){ /* if image is successfully uploaded then imagename is stored in database. */ mysql_query("update student_information set image='$imagename' where student_id='{$_SESSION['user_id']}'", $link_id); $flag = "success"; if(mysql_error()!=null){ die(mysql_error()); } }else{ if(file_exists('images/' . $imagename)) { unlink('images/' . $imagename); } rollbackData(); } }else{ if(file_exists('images/' . $imagename)) { unlink('images/' . $imagename); } rollbackData(); die("You can upload image of 1 MB size only. Please, try again."); } }else{ if(file_exists('images/' . $imagename)) { unlink('images/' . $imagename); } rollbackData(); die("You can upload images of .jpg, .jpeg, .gif extensions only. Please, try again. "); } }else{ $flag="error"; } if($flag == "success"){ mysql_query(" COMMIT "); $flag="success"; if(mysql_error() != null){ die(mysql_error()); } } header("location:Student_Edit.php?flag=$flag"); die(); ?> the problem left now is the image wont upload and it flags the error. i know this has been a lot but i need you to help me modify these codes.
  8. ok got it ben,, i think i would accept your suggestion to keep registration process simple, that is always what im thinking all night long, thank you for confirming it. i'll work the codes now and put the adding of image on the Update profile. Please stand by Ben, i may need your help after this ;-)
  9. Yes Ben, I understand your codes in fact that is what i am using. Actually, this is still on the process when the student register themselves-Registration_handler.php'. I suppose in this instance the student_id is not yet created. This is the registration page where the student filled-up information including the uploading of their image.
  10. Sorry to bother you Ben, There has been slightly changes since i am also working in solving the scenario. here is now my current codes. if($_FILES['image']['name'] != ""){ $filename = $_FILES['image']['name']; $ext = strrchr($filename,"."); $imagename = $student_id; $imagename .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['image']['size']; if($size > 0 && $size < 1000000){ $archive_dir = "images"; $userfile_tmp_name = $_FILES['image']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, $archive_dir .'/'. $student_id .'_'. $imagename .'.'. $ext)){ this codes can upload an image. there is no error. the image is uploaded succesfully. Example if the uplaoded file has a file name pic.jpg,,after it has been succesfully upload it is rename to "_pic.jpg" without the quotes just underscore and the file name itself. What i wanted is to rename it to its unique student_id number so i can display it smoothly to another page.
  11. This is so far what i got Ben and i failed to rename the uploaded file to its $student_id. if($_FILES['image']['name'] != ""){ $filename = $_FILES['image']['name']; $ext = strrchr($filename,"."); $imagename = $student_id; $imagename .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['image']['size']; if($size > 0 && $size < 1000000){ $archive_dir = "images"; $userfile_tmp_name = $_FILES['image']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, "$archive_dir/$imagename")){ The file has been succesfully uploaded Ben but help me to insert the codes which to rename its file name to its student_id so i can display it to another page smoothly.
  12. Hello Admins and Php Freaks, I have manage to upload the image using this codes $student_id = $_POST['student_id']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $gender = $_POST['gender']; $date_of_birth = date("Y-m-d",strtotime($_POST['date_of_birth'])); $contact_no = $_POST['contact_no']; $grade = $_POST['grade']; $section = $_POST['section']; $LRN = $_POST['LRN']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $address = $_POST['address']; $description = $_POST['description']; $LRCardname= ""; $LRCard2name= ""; $query = "UPDATE student_information SET first_name='$first_name',last_name='$last_name',"; $query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',"; $query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description'"; $query .= " WHERE student_id='$student_id'"; $result = mysql_query($query, $link_id); if(mysql_error() != null){ die(mysql_error()); } /* This block shows the start codes for the upload of the Learner Report Card. */ if($result){ if($_FILES['LRCard']['name'] != ""){ $filename = $_FILES['LRCard']['name']; $ext = strrchr($filename,"."); $LRCardname = $student_id; $LRCardname .="_". $filename; if($ext ==".jpg" || $ext ==".jpeg" || $ext ==".JPG" || $ext ==".JPEG" || $ext ==".gif" || $ext ==".GIF"){ $size = $_FILES['LRCard']['size']; if($size > 0 && $size < 5000000){ $archive_dir = "LRCards"; $userfile_tmp_name = $_FILES['LRCard']['tmp_name']; if(move_uploaded_file($userfile_tmp_name, "$archive_dir/$LRCardname")){ /* if LRC is successfully uploaded then LRC is stored in database. */ mysql_query("update student_information set LRCard='$LRCardname' where student_id='$student_id'", $link_id); $flag = "success"; if(mysql_error()!=null){ die(mysql_error()); } } else{ if(file_exists('LRCard/' . $LRCardname)) { unlink('LRCards/' . $LRCardname); } rollbackData(); } } else{ if(file_exists('LRCards/' . $LRCardname)) { unlink('LRCard/' . $LRCardname); } rollbackData(); die("You can upload LRCard of 5 MB size only. Please, try again."); } } else{ if(file_exists('LRCards/' . $LRCardname)) { unlink('LRCards/' . $LRCardname); } rollbackData(); die("You can upload LRCard of .jpg, .jpeg, .gif extensions only. Please, try again. "); } } } else{ $flag="error"; } if($flag == "success"){ mysql_query(" COMMIT "); $flag="success"; if(mysql_error() != null){ die(mysql_error()); } } Now i want to display this uploaded image with respect to a specific student with auto incremented unique number. You know Admin Ben that i always doing my best to get those codes but this time i think im lost. I want this image to be displayed on another page. Please help me this time with the codes and ill do the rest. Please and another please. I always beleive in your expertise in CRUDE.
  13. phpNOvice

    Error In Updating Learner Information

    Hello Ben, hahaha,, i am so dumb!! Why i haven't think of that....thank you for that hint Ben.. I solve it,,and for the benefit of those future reader on this thread. ill post the solution. $query = "UPDATE student_information SET learner_id='$learner_id',first_name='$first_name',last_name='$last_name',"; $query .= "gender='$gender',date_of_birth='$date_of_birth',contact_no='$contact_no',grade='$grade',section='$section',"; $query .= "LRN='$LRN',email1='$email1',email2='$email2',address='$address',description='$description'"; $query .= " WHERE student_id='{$_SESSION['user_id']}'"; $result = mysql_query($query, $link_id); if(mysql_error() != null){ die(mysql_error()); } else{ $flag="success"; } header("location:Student_Edit.php?flag=$flag&student_id='{$_SESSION['user_id']}'"); ?> Thank you Ben.
×