473,549 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ 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 1426
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
2856
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 write.... any ideas why?? <?php include 'gall_settings.inc';
5
3239
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 want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a thumbnail? How do I pass the uploaded .jpg to a stored...
3
1960
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 that doesn't seem to be reliable; for example if you rename an .exe to .jpg and upload using Firefox, it returns "image/jpeg" (IE 6 returns...
14
2786
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 check image dimension when uploaded so that any fake image that is actually a text file is blocked (user renames a .txt to .gif, e.g.). However, a png...
2
2005
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 this. A good commercial comparison is as follows; I uploaded a photo to www.flickr.com....
1
1820
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 the photo, then it will go to the photo full sreen.. I don't know how to make the script for put it into the gallery.. best regards, Erwin Chrisman
0
2060
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 define the area in Montreal.) YYYYMM reveals the year and month that the photo was taken based on EXIF data. 222 allows for 999 photos of a given...
3
4406
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 when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true"...
7
2481
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 upload that filename to a mysql database (users.photo). This is my code.. it shows no errors but it does not add it to my server. HELP WOULD BE...
0
7521
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6044
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3501
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.