Page 1 of 1
capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 12:42 pm
by sleepydad
I have created a database with a table column that I've named 'photo'. Ultimately what I'm looking to do is offer my users the option to upload photos to a folder, capture that photo name and insert that name into the photo column of my table. Currently my HTML reads (abbreviated):
<form action='process.php' method='post'>
<input type="file" name="photo">
</form>
I've tried in my php using:
$path="images/";
$photo=basename($_FILES['photo']);
$photo=$path.$photo;
All that inserts into the database is the "images/". The photo name is stripped away, or never captured at all.
Solution(s)??
Thanks in advance -
sleepydad
Re: capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 1:28 pm
by John Cartwright
What does
Code: Select all
echo '<pre>';
print_r($_FILES);
echo '</pre>';
reveal after an upload?
Re: capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 2:23 pm
by sleepydad
Thank you John. That resulted in:
Array
(
[photo] => Array
(
[name] => cut.png
[type] => image/png
[tmp_name] => /Applications/MAMP/tmp/php/phpGQZ1uk
[error] => 0
[size] => 6155
)
)
Now how do I 'grab' [name]. Sorry, I'm pretty new to php.
Thanks again -
Re: capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 2:33 pm
by John Cartwright
Re: capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 2:51 pm
by sleepydad
Cool. That got the file name. One more question, and I promise I'll leave you all alone (for today anyway!) ..
When I hit the submit button, it prints the print_r() in the browser window. Any way to suppress that so my visitors don't have to see it, yet still maintain the functionality that we've acheived?
Re: capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 3:20 pm
by sleepydad
Hey! Figured something out on my own!
$photoName=($_FILES['photo']['name']);
Thanks again, John, for the assistance.
sleepydad
Re: capturing photo name for insertion into mysql
Posted: Fri Feb 13, 2009 3:55 pm
by John Cartwright
You can remove the echo '<pre> print_r stuff. That was strictly for debugging purposes.