473,383 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Adding number to image upload name

155 100+
The below is turning up an error message - Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Expand|Select|Wrap|Line Numbers
  1. $imagepath = ".$_SESSION['user_id']."."_"."$imagepath";
I'm trying to ad the user_id to an uploaded image name to make it unique and identifiable.
Jun 24 '09 #1
2 1682
Markus
6,050 Expert 4TB
@DavidPr
That makes no sense - Why start the string just to close it immediately?

Anyway, double-quoted strings parse any variables within them - so you don't need to concatenate them in.

Expand|Select|Wrap|Line Numbers
  1. $imagepath = "{$_SESSION['user_id']}_{$imagepath}";
  2. // or
  3. $imagepath = $_SESSION['user_id'] . '_' . $imagepath;
  4.  
Jun 24 '09 #2
DavidPr
155 100+
OK, nothing I've tried thus far has even remotely worked.

I have to create a unique name for the image. I would like to use the user's user_id to do this. This way I can identify the photo as belonging to whomever.

The images aren't stored in the database, just the name and sizes. But the image_name in the database will be the same as the image names of the photos in the folders - pgallery/ and pgallery/thumbs, and will be used in a script to display the images.

Ideally the image name would look like this in the database and in the folders: 12_boat.jpg - where 12 is the person's user_id. But how to do this?

Here's the image script:

Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['submit'])){
  2.   if (isset ($_FILES['new_image'])){
  3.       $imagename = $_FILES['new_image']['name'];
  4.       $source = $_FILES['new_image']['tmp_name'];
  5.  
  6.       $target = "./../pgallery/".$imagename;
  7.       move_uploaded_file($source, $target);
  8.  
  9.       $imagepath = $imagename;
  10.  
  11.       $save = "./../pgallery/" . $imagepath; //This is the new file you saving
  12.       $file = "./../pgallery/" . $imagepath; //This is the original file
  13.  
  14.       list($width, $height) = getimagesize($file) ; 
  15.  
  16.       $b_width = 640;
  17.       $b_height = 480;
  18.  
  19.  
  20. if($width > $height) 
  21.       $diff = $width / $b_width;
  22.       $b_height = $height / $diff; 
  23.  
  24. }
  25. elseif($height >= $width) 
  26.       $diff = $height / $b_height;
  27.       $b_width = $width / $diff; 
  28. }
  29.  
  30.  
  31.  
  32.  
  33.       $tn = imagecreatetruecolor($b_width, $b_height) ; 
  34.       $image = imagecreatefromjpeg($file) ; 
  35.       imagecopyresampled($tn, $image, 0, 0, 0, 0, $b_width, $b_height, $width, $height) ; 
  36.  
  37.       imagejpeg($tn, $save, 100) ; 
  38.  
  39.       $save = "./../pgallery/thumbs/" . $imagepath; //This is the new file you saving
  40.       $file = "./../pgallery/" . $imagepath; //This is the original file
  41.  
  42.       list($b_width, $b_height) = getimagesize($file) ; 
  43.  
  44.       $t_width = 100; 
  45.       $t_height = 100;
  46.  
  47.  
  48. if($b_width > $b_height) 
  49.       $diff = $b_width / $t_width;
  50.       $t_height = $b_height / $diff; 
  51.  
  52. }
  53. elseif($b_height >= $b_width) 
  54.       $diff = $b_height / $t_height;
  55.       $t_width = $b_width / $diff; 
  56. }
  57.  
  58.  
  59.  
  60.  
  61.       $tn = imagecreatetruecolor($t_width, $t_height) ; 
  62.       $image = imagecreatefromjpeg($file) ; 
  63.       imagecopyresampled($tn, $image, 0, 0, 0, 0, $t_width, $t_height, $b_width, $b_height) ; 
  64.  
  65.       imagejpeg($tn, $save, 100) ; 
  66.  

What this script does is take a large image file and reduce it in size. It is this reduced image that is put in the pgallery folder and is used to create the thumbnail image that will go into the pgallery/thumbs folder.
Jun 24 '09 #3

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

Similar topics

15
by: lawrence | last post by:
I've been using the following function (yes, it is inelegant, what can I say, I wrote it a long time ago) to upload images. Haven't had a problem with it for at least a year, and I don't recall...
6
by: lawrence | last post by:
I've the form you see below, which is supposed to upload an image. I expect the image name as a var to be $uploadedFile. In the receiving function, I've this code: global $uploadedFile,...
4
by: DH | last post by:
I have a "file upload form" that works OK, but I have been unsuccessful in my attempt to also resize the uploaded .JPG (if it is too wide), over-writing the original .JPG, and then create and save...
3
by: mark | r | last post by:
ok, so i now know how to add, edit, delete and search for products (havent figured out categorisation out yet tho) - how do i upload an image and save the file name to the database as part of the...
0
by: doffer | last post by:
I want to make a portfoliosystem where user can register and get their own portfolio... I've started the developer work, but I'm stuck on the image upload part... I'm experiencing some problems...
0
by: aris1234 | last post by:
hello.. How to upload image file in page update ..?? i have logic like this : if user upload new image then old image must delete and update DB used new name if user not upload new image then...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
1
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
6
AaronL
by: AaronL | last post by:
Hello, I'm designing an e-commerce page and had a few questions. What is the best way to edit a record? For example, I want to put an admin page together where I can edit an item for sale,...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.