[PHP-DB] Code for File Upload
I have been seeing a lot of talk about file uploads. I wrote the following code and it works well when uploading images. The actual image is not stored in the database just the name of the image. When you want to view the image just query the database and include the database variable in your IMG SRC tag. IMG SRC = http://www.path to image $image_name. ? // includes include(config.php); ? ? // Validate entries if ($_REQUEST[pic_category] == ) { echo Must enter a Category for the pictures to go in.; exit; } if ($_FILES['userfile']['size'] == 0) { echo No size; exit; } if ($_FILES['userfile']['type'] == text/plain) { echo cannot upload text it must be an image; exit; } // Set Name of Image for Database entry. This comes from the input fields in the HTML form. $pic_1 = $_FILES['userfile']['name']; $pic_2 = $_FILES['userfile_2']['name']; $pic_3 = $_FILES['userfile_3']['name']; $pic_4 = $_FILES['userfile_4']['name']; $pic_5 = $_FILES['userfile_5']['name']; $pic_6 = $_FILES['userfile_6']['name']; // Path to where images are to be uploaded $upfile = /home/SOMEWHERE/php/photos/.$_FILES['userfile']['name']; $upfile_2 = /home/SOMEWHERE/php/photos/.$_FILES['userfile_2']['name']; $upfile_3 = /home/SOMEWHERE/php/photos/.$_FILES['userfile_3']['name']; $upfile_4 = /home/SOMEWHERE/php/photos/.$_FILES['userfile_4']['name']; $upfile_5 = /home/SOMEWHERE/php/photos/.$_FILES['userfile_5']['name']; $upfile_6 = /home/SOMEWHERE/php/photos/.$_FILES['userfile_6']['name']; // Upload files to the $upfile Directory if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile); move_uploaded_file($_FILES['userfile_2']['tmp_name'], $upfile_2); move_uploaded_file($_FILES['userfile_3']['tmp_name'], $upfile_3); move_uploaded_file($_FILES['userfile_4']['tmp_name'], $upfile_4); move_uploaded_file($_FILES['userfile_5']['tmp_name'], $upfile_5); move_uploaded_file($_FILES['userfile_6']['tmp_name'], $upfile_6); } else { echo Possible file upload attack. Filename: . $_FILES['userfile']['name']; } // Print out the files that were uploaded echo file was uploaded BR . $_FILES['userfile']['name']; echo BR . $_FILES['userfile_2']['name']; echo BR . $_FILES['userfile_3']['name']; echo BR . $_FILES['userfile_4']['name']; echo BR . $_FILES['userfile_5']['name']; echo BR . $_FILES['userfile_6']['name']; ? ? // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die (Unable to connect!); // Place the picture name and captions in the database $query = INSERT INTO table name and so on and so on Hope this will helps! Wade -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer Bayou Internet...(888) 30-BAYOU...http://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SESSIONS
How would one go about registering a session if you were to create the session based on the users ID and NAME from the database. I have the users ID and NAME already being pulled from the database and being stored in variables named $id and $name. I have latest version of PHP so I think I need to use the $_SESSION[] instead of session_register. I am also using the session_encode function to echo out the session that is currently being stored. What I am trying to store and what I am actually seeing printed to the page is entirly different. if (mysql_num_rows($sql_result) == 1) { session_start(); list($id, $name) = mysql_fetch_row($sql_result); $SESSION_ID = $id; $SESSION_NAME = $name; session_register(SESSION_ID); session_register(SESSION_NAME); header(Location:); } else { header(Location:); exit; } -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer Bayou Internet...(888) 30-BAYOU...http://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Difference in time
Hello all, I am fighting a time issue(don't we all). I have a online poll set up. I need a way to stop a person from submitting more than once an hour. As of now I have the time .. mktime( ) .. being stored in a database along with the users IP. I want to be able to say if 1 hour has passed from the time .. mktime( ) .. that is stored in the db they can vote once again. This also has to account that if someone goes to the poll tomorrow at the same time (same hour) the script knows it's a different hour and different day. Scenario: I submit to the poll at 12:00 PM, one hour from now will be 1:00 PM and I can submit again. Now lets say it's 12:00 PM the next day. The database stored time will say 12:00 PM of the day before, It will not let me submit because it thinks that it has to be at least 1:00 PM before I can submit again. Which is wrong. I was trying to use the mktime( ) function but it keeps giving me these results.(( 1033578795 )) The last few numbers change but the first few (that as suppose to be the hour) does not change? mktime(int hour, int minute, int second, int month, int day, int year). How can I use this mktime( ) function to do what I need it to? Am I going in the wrong direction? Thank you very much Wade -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer Bayou Internet...(888) 30-BAYOU...http://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com
Re: [PHP-DB] Flush database
Could anyone help me to figure out how to write a piece of code that says if the time now time( ) is greater than 1 hour of the time( )then do something. I have a script that gets the time as of now and I also have the time of (lets say then) stored in a database. how would I write the code to say if the old time is greater than 1 hour do something? $subtracted_time = $time_now - $stored_database_time; if ($subtracted_time mktime(1,0,0,0,0,0)) Thank you -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Compare time functions
Could anyone help me to figure out how to write a piece of code that says if the time now time( ) is greater than 1 hour of the time( time stored in the database) do something. I have a script that gets the time as of now and I also have the time of (lets say then) stored in a database. how would I write the code to say if the old time is greater than 1 hour do something? I need to compare the 2 time( ) functions. $time1 = current server time $time2 = server time stored in the database if ($time1 is = 1 hour of $time2) { execute code } How would one go about comparing these two time functions? Thank you -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer Bayou Internet...(888) 30-BAYOU...http://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Flush database
I am storing IP addresses in a database, but after an hour has passed I want to delete all the IP addresses from that database. I want to do this based on the server time. Example.. Someone comes to my web page, I store their IP address in my database. So now I write a PHP script that says if that IP returns to my page within an hour, they can't view my page. If they come back after an hour has passed they can view the contents of that page. but only after an hour has passed. Can anyone help me with the syntax or functions that will clear the database after an hour of waiting has passed? Is this possible? Any suggestions, logic or any help on this matter will be greatly appreciated. Thank you -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer Bayou Internet...(888) 30-BAYOU...http://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Flush database
So how would one compare the timestamp? how would you write if timestamp is greater than timestamp + 1 hour { Ok to view page run query to update that IP to new timestamp -- I think this will be better than a delete statement } else { Can't view page } I know you will have to compare the timestamps. the one in the database against the current hit. How would one do this comparison? -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer Bayou Internet...(888) 30-BAYOU...http://www.bayou.com Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php