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
capturing photo name for insertion into mysql
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: capturing photo name for insertion into mysql
What does
reveal after an upload?
Code: Select all
echo '<pre>';
print_r($_FILES);
echo '</pre>';Re: capturing photo name for insertion into mysql
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 -
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 -
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: capturing photo name for insertion into mysql
Code: Select all
echo $_FILES['photo']['name'];Re: capturing photo name for insertion into mysql
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?
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
Hey! Figured something out on my own!
$photoName=($_FILES['photo']['name']);
Thanks again, John, for the assistance.
sleepydad
$photoName=($_FILES['photo']['name']);
Thanks again, John, for the assistance.
sleepydad
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: capturing photo name for insertion into mysql
You can remove the echo '<pre> print_r stuff. That was strictly for debugging purposes.