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 - $imagepath = ".$_SESSION['user_id']."."_"."$imagepath";
I'm trying to ad the user_id to an uploaded image name to make it unique and identifiable.
2 1682 @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. -
$imagepath = "{$_SESSION['user_id']}_{$imagepath}";
-
// or
-
$imagepath = $_SESSION['user_id'] . '_' . $imagepath;
-
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: - if(isset($_POST['submit'])){
-
if (isset ($_FILES['new_image'])){
-
$imagename = $_FILES['new_image']['name'];
-
$source = $_FILES['new_image']['tmp_name'];
-
-
$target = "./../pgallery/".$imagename;
-
move_uploaded_file($source, $target);
-
-
$imagepath = $imagename;
-
-
$save = "./../pgallery/" . $imagepath; //This is the new file you saving
-
$file = "./../pgallery/" . $imagepath; //This is the original file
-
-
list($width, $height) = getimagesize($file) ;
-
-
$b_width = 640;
-
$b_height = 480;
-
-
-
if($width > $height)
-
{
-
$diff = $width / $b_width;
-
$b_height = $height / $diff;
-
-
}
-
elseif($height >= $width)
-
{
-
$diff = $height / $b_height;
-
$b_width = $width / $diff;
-
}
-
-
-
-
-
$tn = imagecreatetruecolor($b_width, $b_height) ;
-
$image = imagecreatefromjpeg($file) ;
-
imagecopyresampled($tn, $image, 0, 0, 0, 0, $b_width, $b_height, $width, $height) ;
-
-
imagejpeg($tn, $save, 100) ;
-
-
$save = "./../pgallery/thumbs/" . $imagepath; //This is the new file you saving
-
$file = "./../pgallery/" . $imagepath; //This is the original file
-
-
list($b_width, $b_height) = getimagesize($file) ;
-
-
$t_width = 100;
-
$t_height = 100;
-
-
-
if($b_width > $b_height)
-
{
-
$diff = $b_width / $t_width;
-
$t_height = $b_height / $diff;
-
-
}
-
elseif($b_height >= $b_width)
-
{
-
$diff = $b_height / $t_height;
-
$t_width = $b_width / $diff;
-
}
-
-
-
-
-
$tn = imagecreatetruecolor($t_width, $t_height) ;
-
$image = imagecreatefromjpeg($file) ;
-
imagecopyresampled($tn, $image, 0, 0, 0, 0, $t_width, $t_height, $b_width, $b_height) ;
-
-
imagejpeg($tn, $save, 100) ;
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
| |