supanoob Posted March 19, 2009 Share Posted March 19, 2009 Basically i have a form, and a checkbox that i want people to check if they are uploading an image when filling out the form. However whenever they check the box all works except the image upload script wont pick up the file name :S Form: <?php if ($_GET['step'] == 'websites_add') { if (!$_SESSION['valid_user']) { echo "You are not logged in, therefore cannot add a website to the database."; DIE(include_once('site_bottom.php')); } echo "<form method=\"post\" action=\"index.php?step=websites_process\" enctype=\"multipart/form-data\"> <table style=\"width: 100%\"> <tr> <td colspan=\"2\" class=\"desc\">Please enter the name of the website you would like to submit. Along with its URL and a brief descrption of the site, the can be upto 500 words, but no less than 50.</td> </tr> <tr> <td style=\"width: 254px\">Website Name:</td> <td><input name=\"name\" type=\"text\" size=\"30\" /></td> </tr> <tr> <td style=\"width: 254px\">Website URL (with the http://):</td> <td><input name=\"url\" type=\"text\" size=\"60\" value=\"http://\" /></td> </tr> <tr> <td style=\"width: 254px\">Website Description:</td> <td><textarea name=\"description\" cols=\"30\" rows=\"5\"></textarea></td> </tr> <tr> <td colspan=\"2\" class=\"desc\">Please select a catagory that you feel this website falls under.</td> </tr> <tr> <td style=\"width: 254px\">Website Catagory</td> <td><select name=\"website_catagory\"> <option value=\"Adult\">Adult </option> <option value=\"Advertising\">Advertising </option> <option value=\"Auto\">Auto </option> <option value=\"Business\">Business </option> <option value=\"Chat\">Chat</option> <option value=\"Cities\">Cities </option> <option value=\"Education\">Education </option> <option value=\"Employment/Jobs\">Employment/Jobs </option> <option value=\"Entertainment\">Entertainment</option> <option value=\"Events\">Events</option> <option value=\"Forums\">Forums</option> <option value=\"Games\">Games </option> <option value=\"Holidays\">Holidays </option> <option value=\"Health\">Health </option> <option value=\"Horoscope\">Horoscope </option> <option value=\"Internet\">Internet </option> <option value=\"Marketing\">Marketing </option> <option value=\"People\">People </option> <option value=\"Places\">Places </option> <option value=\"Real Estate\">Real Estate</option> <option value=\"Search\">Search</option> <option value=\"Science\">Science </option> <option value=\"Sports\">Sports </option> <option value=\"Technology\">Technology </option> <option value=\"Travel\">Travel </option> <option value=\"Weather\">Weather</option> </select></td> </tr> <tr> <td colspan=\"2\" class=\"desc\">You may choose to upload a screenshot of the website you are submitting. This will allow users to see what website they are going to before they go to the site. Please tick the following box if you wish to do so. <input name=\"screenshot\" type=\"checkbox\" /></td> </tr> <tr> <td style=\"width: 254px\">Upload:</td> <td>Select file: <input name=\"ufile\" type=\"file\" id=\"ufile\" size=\"50\" /></td> </tr> <tr> <tr> <td colspan=\"2\" class=\"desc\">By clicking submit you agree that the website you are submitting does not break any terms and conditions, you also agree that you have read the privacy policy regarding submitions of websites (part ##)</td> </tr> <tr> <td style=\"width: 254px\"> </td> <td><input name=\"Submit1\" type=\"submit\" value=\"submit\" class=\"button\"/></td> </tr> </table> </form>"; } ?> PHP: <?php if ($_GET['step'] == 'websites_process') { if (!$_SESSION['valid_user']) { echo "You are not logged in, therefore cannot add a website to the database."; DIE(include_once('site_bottom.php')); } $site_name = $_POST['name']; $site_url = $_POST['url']; $site_desc = $_POST['description']; $site_catagory = $_POST['website_catagory']; $screenshot = $_POST['screenshot']; $site_desc = nl2br($site_desc); $words = str_word_count($site_desc); $ip=$_SERVER['REMOTE_ADDR']; $site_url = parse_url($site_url,PHP_URL_HOST); if ($site_name == '') { echo "The website must have a name"; DIE(include_once('site_bottom.php')); } if ($site_url == '') { echo "Please enter a URL."; DIE(include_once('site_bottom.php')); } if ($site_desc == '') { echo "You must enter a description for the website."; DIE(include_once('site_bottom.php')); } if ($words < 50) { echo "The site Description needs to be more than 50 words."; DIE(include_once('site_bottom.php')); } if ($words > 500) { echo "The site Description should be less than 500 words."; DIE(include_once('site_bottom.php')); } if ($screenshot == 'on') { // Your file name you are uploading $file_name = $_FILES['ufile']['name']; $rand = rand(10000,99999999); echo "$file_name<br>"; //combine random digit to you file name to create new file name //use dot (.) to combile these two variables $new_file_name=$user_id.$rand.$file_name; echo "$new_file_name<br>"; //set where you want to store files //in this example we keep file in folder upload //$new_file_name = new upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif $path= "thehub/images/webshots/".$new_file_name; echo "$path<br>"; if($ufile !=none) { if ($_FILES['ufile']['size'] > 150000) { echo "Your filesize is too big. Please make sure it is less than 25KB."; DIE(); } if(copy($_FILES['ufile']['tmp_name'], $path)) { $ext = strtolower(substr(strrchr($new_file_name, '.'), 1)); if ($ext == 'jpeg' OR $ext == 'jpg' OR $ext == 'gif') { echo "Image has been uploaded.<BR/>"; } else { $delete_file = "thehub/images/webshots/".$new_file_name; unlink($delete_file); echo "The file type is not valid. Please make sure the file type is jpeg, jpg or gif, and is no bigger than 150KB in size."; DIE(); } } else { echo "There has been an error. Please ensure your file size is less than 150KB."; } } } else if ($screenshot == 'off') { $new_file_name = 'no_screenshot.jpg'; } $query="insert into websites (website_name, website_url, website_desc, website_catagory, added_by, added_by_ip, website_img) values ('$site_name', '$site_url', '$site_desc', '$site_catagory', '$user_id', '$ip', '$new_file_name')"; $result=mysql_query($query); echo "$screenshot<br><br>"; echo "Website has been successfully added to the database. You IP $ip has been stored along with it to try and control abuse. "; } ?> Link to comment https://forums.phpfreaks.com/topic/150117-image-upload/ Share on other sites More sharing options...
supanoob Posted March 19, 2009 Author Share Posted March 19, 2009 Anyone? Link to comment https://forums.phpfreaks.com/topic/150117-image-upload/#findComment-788413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.