473,386 Members | 1,842 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,386 software developers and data experts.

file upload as "idnumber".bmp

Any help appreciated.

I have a form that does pretty well to collect data and upload a
persons picture to a directory on a server.

The part of the form that does the latter is:
copy($HTTP_POST_FILES['PhotoUpload']['tmp_name'],

"directory/pictures/" . $firstName . " " . $lastName . ".bmp" );

-------
So the file will save on the sever as "firstname lastname".bmp

But of course when people with the same name register, there is an
overwrite, plus for another application I would like the photo name to
be "idnumber.bmp"

At the moment the server adds a new id nuber for each line added to
the database and so there is a variable passing around called
$idnumber

I thought that I could make the above changed to this:

copy($HTTP_POST_FILES['PhotoUpload']['tmp_name'],

"directory/pictures/" . $idnumber . ".bmp" );
------

but this doesn't seem to work because I don't think that this value is
given a value until everything is posted to the server - which makes
sense because the id number is the unique incremental value given to
each row of the database.
Does anyone know how I can change this form to get it to do what I
need?

Thanks for any help

Matt

May 4 '07 #1
2 1582
On May 4, 4:01 pm, m...@londonstudent.co.uk wrote:
Does anyone know how I can change this form to get it to do what I
need?

Thanks for any help

Matt
You have to move the uploaded file after you insert whatever it is you
insert into the database so you can get the new ID number. The most
efficient way of retrieving this incremented ID depends on how you are
connecting to MySQL. If you are using the regular MySQL interface, you
can get the ID number back out by using the mysql_insert_id() function
immediately after your INSERT statement. If you are using MySQLi (non-
procedural version), you can use $MySQLiObj->insert_id.

Also, when dealing with uploaded files, for security reasons it's
usually best to use the move_uploaded_file() function instead of
copy(). But you may already be checking the uploaded file using
is_uploaded_file(). move_uploaded_file() just does both at once.

So here's an idea of what should work:

<?php
//...validation, DB connection, etc...

if( !$db->query( "INSERT INTO `it` ( `...`, `...` ) VALUES ( '...',
'...' )" ) )
{
$uhOh = "Query failed: $db->error";
}

else if( !move_uploaded_file( $_FILES['PhotoUpload']['tmp_name'],
"directory/pictures/$db->insert_id.bmp" ) )
{
$uhOh = 'Could not move uploaded file';
}

//...
?>

-Mike PII

May 4 '07 #2
On May 4, 11:32 pm, Mike P2 <sumguyovrt...@gmail.comwrote:
On May 4, 4:01 pm, m...@londonstudent.co.uk wrote:
Does anyone know how I can change this form to get it to do what I
need?
Thanks for any help
Matt

You have to move the uploaded file after you insert whatever it is you
insert into the database so you can get the new ID number. The most
efficient way of retrieving this incremented ID depends on how you are
connecting to MySQL. If you are using the regular MySQL interface, you
can get the ID number back out by using the mysql_insert_id() function
immediately after your INSERT statement. If you are using MySQLi (non-
procedural version), you can use $MySQLiObj->insert_id.

Also, when dealing with uploaded files, for security reasons it's
usually best to use the move_uploaded_file() function instead of
copy(). But you may already be checking the uploaded file using
is_uploaded_file(). move_uploaded_file() just does both at once.

So here's an idea of what should work:

<?php
//...validation, DB connection, etc...

if( !$db->query( "INSERT INTO `it` ( `...`, `...` ) VALUES ( '...',
'...' )" ) )
{
$uhOh = "Query failed: $db->error";

}

else if( !move_uploaded_file( $_FILES['PhotoUpload']['tmp_name'],
"directory/pictures/$db->insert_id.bmp" ) )
{
$uhOh = 'Could not move uploaded file';

}

//...
?>

-Mike PII
mike has answered already, im just adding an off topic point, when you
say "another application" do you use the same table to authenticate
both sets of users as well as the same table to store data regarding
pictures and so on, if you do remember that while one app might be
"aunty mable's semi-naughty hen night shinanigans" the other might be
"important child protection work data" one day you might create a test/
test account for auntymabels friends who says she cant login, and
anyway you won't require strong passwords on the mabel app cos its
only a bunch of computer-phobics. This adds up to, cross contamination
of data, sql injection based on same privaledges for the mysql user
for boths apps, increasing the surface area for easy hacks to occur in
both apps.
It would be safer to [create a new db per app and] copy the table when
sets of users unmixed, and give each app a non-privaledged user which
just has usage of that particular app's auth table.
(I once knew a man from london whose mysql server was completely
undone - no honest I really did, for this very reason)
ttfn, m

May 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Amy Kimber | last post by:
Hello all, ok, I have a file upload secton to my site, two pages, one with a form and one that does the uploading.... some files upload fine, other don't an exe of 300k will upload, but a...
15
by: Simon | last post by:
I would like to create a very basic file upload add image form to add to my web site and to keep them in a "tmp" directory within my web hosting file manager once uploaded. I understand the basic...
3
by: Bijoy Naick | last post by:
I've written a simple file upload user control in VB .NET. It comprises of an InputFile HTML Server Control, an Upload button and a message label. User clicks on the Browse button of the...
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
3
by: Mike Kelly | last post by:
Hi. I've built a page using standard ASP.NET 2.0 features and when I upload a large file (>20MB) to our intranet server, I get a paltry 100KB/s on our 100Mb/s LAN. Simply copying the file, I get...
6
by: Marko Vuksanovic | last post by:
I am trying to implement a file upload progress indicator (doesn't have to be a progress bar) using atlas... I do realize that the indicator cannot be implemented using Update panel control, but is...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
3
by: shapper | last post by:
Hello, I need to upload a file. Can I only do this with the File Upload control? I also need the following: - Send upload info, upload percentage, continuously to a JavaScript function so...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.