473,465 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Renaming uploaded photo

20 New Member
Hello bytes,

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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     session_start();
  3.     $session_id = $_SESSION['user_id'];
  4.     if($session_id == null){
  5.        header("location:Student_Edit.php");
  6.        die();
  7.     }
  8.     include 'Connect.php';
  9.     $flag = "";
  10.     $result = mysql_query("SELECT * FROM student_information where student_id='{$_SESSION['user_id']}'",$link_id);;
  11.     $data = mysql_fetch_array($result);
  12. ?>     
  13. <div class="style3" >
  14.     <?php
  15.     $uploadpath = 'upload/';     
  16.     $max_size = 2000;         
  17.     $alwidth = 900;           
  18.     $alheight = 800;          
  19.     $allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png','psd');       
  20.     if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
  21.     $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);      
  22.     $sepext = explode('.', strtolower($_FILES['fileup']['name']));
  23.     $type = end($sepext);      
  24.     list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);     
  25.     $err = '';         
  26.     if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
  27.     if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
  28.     if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
  29.     if($err == '') {
  30.     if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) { 
  31.       echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
  32.       echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
  33.       echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
  34.       if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height;
  35.       echo '<br/><br/>Image address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>';
  36.     }
  37.     else echo '<b>Unable to upload the file.</b>';
  38.   }
  39.   else echo $err;
  40. }
  41. ?>
  42.  
Please modify my codes to rename the uploaded file to the student id of the student who is uploading it.
Aug 14 '14 #1
2 1418
Exequiel
288 Contributor
maybe you can try this one.
Expand|Select|Wrap|Line Numbers
  1.  
  2. $FILENAME         =     $FILENAME;//file name of your uploaded file.
  3.     $newName        =    'image_'.date("Ymdg:i a").'_'.$FILENAME;//get the name of the image uploaded and add some dates etc. to rename your uploaded image.
  4.  
  5.     $temp             =     "uploads/temp_img/".$FILENAME;//temporary folder for uploaded file,
  6.     $profile         =     "uploads/profile/".$newName;//the folder where to move the image
  7.  
  8.     $move_upload     =     rename($temp,$profile);
  9.  
  10.     if($move_upload)
  11.     {
  12.         echo 'Success';
  13.     }
  14.     else
  15.     {
  16.         echo 'Mali.';
  17.     }
  18.  
Aug 15 '14 #2
hanspeare
20 New Member
thank you exequiel..
Aug 18 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: matt | last post by:
I have this code, works perfectly on Windows server, but now i'm trying to run it on a Linux server, the form submits, i get no errors, but the photo doesnt upload, and the caption file doesnt...
5
by: bob garbados | last post by:
I am trying to create a database-driven photo gallery for a friend with an admin form to upload images... I can upload a file to the web server, but I want to store the image in a database and I...
3
by: Chris Mahoney | last post by:
Hi I'm setting up a site where users will be able to upload photos. I'd like to be able to ensure that they're uploading JPEGs, and not malicious code. I've tried checking the MIME type, but...
14
by: =?Utf-8?B?U2FtdWVs?= | last post by:
Hi, I have a web app that allows others to upload files, and the problem is that if I allow users to upload image files, fake image can be uploaded and cause XSS issues. In the app, I do...
2
by: RickVidallon | last post by:
I have a .Net application written in C# where members may upload their photos and have them displayed on our website. We are trying to maintain the best quality using best settings in .Net for...
1
by: popotz | last post by:
Hi..I really need a big help.. I was wondering how to make my own photo gallery for my own website. The photo must be uploaded first, and then it automaticly putted into the gallery..if we click...
0
by: brendan | last post by:
I'm trying to write a code that batch renames photos. In the end each photo should be named: AABBB1111YYYYMM222 where AABBB1111 defines a given place. (i.e. CAMTL = montreal and four digits...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
7
by: nwclark | last post by:
Ok... I have a noobie issue. I am trying to upload a photo to specific directory on my server. (this is working correctly with the code below). However, I am also trying to rename the file and...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.