Synook Posted August 9, 2007 Share Posted August 9, 2007 Hrmm... is there an 'uploads' folder currently? Try chmodding it to 777 Link to comment Share on other sites More sharing options...
imrie Posted August 9, 2007 Author Share Posted August 9, 2007 Yes there is and it is all ready on 777 Link to comment Share on other sites More sharing options...
imrie Posted August 9, 2007 Author Share Posted August 9, 2007 I will post all coding if it helps:Form: html><head><title>HTML Form for uploading image to server</title></head><body><form action="form3.php" method="post" enctype="multipart/form-data"><p>Skin File:<input type="file" name="file" /> <br>Image:<input type="file" name="file" /> <br>Title:<input type="text" name="Title" /><br>Author:<input type="text" name="Author" /><br>Category: <select name="options"> <option value="CLAAS_Cougar ">CLAAS_Cougar </option> <option value="CLAAS_Disco ">CLAAS_Disco </option> <option value="CLAAS_Round Baler ">CLAAS_Round Baler </option> <option value="CLAAS_Xerion">CLAAS_Xerion</option> <option value="Delvano_Sprayer">Delvano_Sprayer</option> <option value="Disc_Harrow">Disc_Harrow</option> <option value="Forage_Harvester ">Forage_Harvester </option> <option value="Grain_Cart">Grain_Cart</option <option value="Grain_Trailer">Grain_Trailer</option> <option value="Header_Trailer ">Header_Trailer </option> <option value="John_Deere_7810">John_Deere_7810</option> <option value="John_Deere_7920 ">John_Deere_7920 </option> <option value="John_Deere_8310">John_Deere_8310</option> <option value="John_Deere_8310t">John_Deere_8310 T </option> <option value="John_Deere_Corn_Header">John_Deere_Corn_Header </option> <option value="John_Deere_Corn_Seeder">John_Deere_Corn_Seeder</option> <option value="John_Deere_Front_Loader">John_Deere_Front_Loader </option> <option value="John_Deere_Machine_40">John_Deere_Machine_40 </option> <option value="John_Deere_Seeder">John_Deere_Seeder </option> <option value="John_Deere_Square_Baler">John_Deere_Square_Baler </option> <option value="John_Deere_STS">John_Deere_STS </option> <option value="John_Deere_Telehandler">John_Deere_Telehandler </option> <option value="John_Deere_Tiller">John_Deere_Tiller </option> <option value="Lexion">Lexion</option> <option value="Livestock_Trialer">Livestock_Trialer</option> <option value="Manure_spreader">Manure_spreader </option> <option value="Manure_Tanker">Manure_Tanker</option> <option value="Miscellaneous">Miscellaneous</option> <option value="New_Holland_NCR">New_Holland_NCR</option> <option value="New_Holland_TG">New_Holland_TG </option> <option value="Plough">Plough</option> <option value="Truck">Truck</option> </select><input type="submit" value="Send" /></p></form></body></html> Script: <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ $success = true; $type = $_FILES['file']['type'];$Title=$_POST['Title']; $Author=$_POST['Author']; if ($type == "image/gif" || $type == "image/jpeg" || $type == "image/bmp") { //upload image if ($_FILES['file']['size'] > 500000) { echo "Error: The image is too large!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"/image_uploads/" . $_FILES["file"]["name"]); if (file_exists("PATH" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } } } else if ($type == "application/rar" || $type == "application/zip" || $type = "application/x-zip-compressed") { //Upload file if ($_FILES['file']['size'] > 1500000) { echo "Error: The file is too large!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"/uploads/" . $_FILES["file"]["name"]); if (file_exists("PATH" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } } } else { //Invalid file type $success = false; echo "Error: File type $type not valid"; } if ($success) { mysql_connect("","imrieimag", "");mysql_select_db("imrieimag");$query = "INSERT INTO `" . $_POST['options'] . "` (title, author, file_name,image) VALUES ('$_POST[Title]', '$_POST[Author]', '$_FILES[file][name]','$_FILES[file][name]')"; mysql_query($query); }}?> Link to comment Share on other sites More sharing options...
imrie Posted August 9, 2007 Author Share Posted August 9, 2007 I made another directory and tried it with that...got the same error. Link to comment Share on other sites More sharing options...
Synook Posted August 9, 2007 Share Posted August 9, 2007 Hrmmmmm.... that is very weird. Perhaps you may have to wait until someone else has a look, I don't know what could be going wrong. ForbiddenYou don't have permission to access /uploads/ on this server.Are you sure it is chmodded to 777? Link to comment Share on other sites More sharing options...
imrie Posted August 9, 2007 Author Share Posted August 9, 2007 Yes, but there is no content in it, also it shouldnt matter as the image is working.I get a "website declined to show page"error Link to comment Share on other sites More sharing options...
Synook Posted August 9, 2007 Share Posted August 9, 2007 Oh... hrmm... try changing the move_uploaded_file() lines to this: move_uploaded_file($_FILES["file"]["tmp_name"],"image_uploads/" . $_FILES["file"]["name"]); and move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); Now it should work! I hope. Link to comment Share on other sites More sharing options...
imrie Posted August 9, 2007 Author Share Posted August 9, 2007 Thanks that fixed it, but.. the file in the database in: Array[name] ,instead of a url. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 9, 2007 Share Posted August 9, 2007 You're not using the correct syntax for arrays inside a string. Instead of something like this:...'$_FILES[file][name]'...you need this:...'{$_FILES['file']['name']}'... Link to comment Share on other sites More sharing options...
imrie Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks, that fixed it.Only one problem. The image and file are the same in the data base. For example i upload merlo.zip and jaguar.bmp, i type test and test for the next 2 fields, and choose a category,It appears in the database as: merlo.zip, merlo.zip, test, test. <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ $success = true; $type = $_FILES['file']['type'];$Title=$_POST['Title']; $Author=$_POST['Author']; if ($type == "image/gif" || $type == "image/jpeg" || $type == "image/bmp") { //upload image if ($_FILES['file']['size'] > 500000) { echo "Error: The image is too large!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"image_uploads/" . $_FILES["file"]["name"]); if (file_exists("PATH" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } } } else if ($type == "application/rar" || $type == "application/zip" || $type = "application/x-zip-compressed") { //Upload file if ($_FILES['file']['size'] > 150000000) { echo "Error: The file is too large!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); if (file_exists("PATH" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } } } else { //Invalid file type $success = false; echo "Error: File type $type not valid"; } if ($success) { mysql_connect("","imrieimag", "");mysql_select_db("imrieimag");$query = "INSERT INTO `" . $_POST['options'] . "` (title, author, Image_file, File) VALUES ('$_POST[Title]', '$_POST[Author]', '{$_FILES['file']['name']}','{$_FILES['file']['name']}')"; mysql_query($query); }}?> form: <html><head><title>HTML Form for uploading image to server</title></head><body><form action="form3.php" method="post" enctype="multipart/form-data"><p>Skin File:<input type="file" name="file" /> <br>Image:<input type="file" name="file" /> <br>Title:<input type="text" name="Title" /><br>Author:<input type="text" name="Author" /><br>Category: <select name="options"> <option value="CLAAS_Cougar ">CLAAS_Cougar </option> <option value="CLAAS_Disco ">CLAAS_Disco </option> <option value="CLAAS_Round Baler ">CLAAS_Round Baler </option> <option value="CLAAS_Xerion">CLAAS_Xerion</option> <option value="Delvano_Sprayer">Delvano_Sprayer</option> <option value="Disc_Harrow">Disc_Harrow</option> <option value="Forage_Harvester ">Forage_Harvester </option> <option value="Grain_Cart">Grain_Cart</option <option value="Grain_Trailer">Grain_Trailer</option> <option value="Header_Trailer ">Header_Trailer </option> <option value="John_Deere_7810">John_Deere_7810</option> <option value="John_Deere_7920 ">John_Deere_7920 </option> <option value="John_Deere_8310">John_Deere_8310</option> <option value="John_Deere_8310t">John_Deere_8310 T </option> <option value="John_Deere_Corn_Header">John_Deere_Corn_Header </option> <option value="John_Deere_Corn_Seeder">John_Deere_Corn_Seeder</option> <option value="John_Deere_Front_Loader">John_Deere_Front_Loader </option> <option value="John_Deere_Machine_40">John_Deere_Machine_40 </option> <option value="John_Deere_Seeder">John_Deere_Seeder </option> <option value="John_Deere_Square_Baler">John_Deere_Square_Baler </option> <option value="John_Deere_STS">John_Deere_STS </option> <option value="John_Deere_Telehandler">John_Deere_Telehandler </option> <option value="John_Deere_Tiller">John_Deere_Tiller </option> <option value="Lexion">Lexion</option> <option value="Livestock_Trialer">Livestock_Trialer</option> <option value="Manure_spreader">Manure_spreader </option> <option value="Manure_Tanker">Manure_Tanker</option> <option value="Miscellaneous">Miscellaneous</option> <option value="New_Holland_NCR">New_Holland_NCR</option> <option value="New_Holland_TG">New_Holland_TG </option> <option value="Plough">Plough</option> <option value="Truck">Truck</option> </select><input type="submit" value="Send" /></p></form></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted August 10, 2007 Share Posted August 10, 2007 The code is only processing one file, but it does it twice. Both times you are processing the file you are referring to $_FILES['file']. So they are both the same file. Check the reference for uploading multiple files:http://www.php.net/manual/en/features.file...ad.multiple.php Link to comment Share on other sites More sharing options...
imrie Posted August 10, 2007 Author Share Posted August 10, 2007 Ahhhh...ok, so i will just replace the refrences to the image file with: $_FILES["file1"]["name"] Link to comment Share on other sites More sharing options...
imrie Posted August 10, 2007 Author Share Posted August 10, 2007 Guys, i cant thank you enough for the help. Thats my upload form complete now. Im going to have to upload all the files to the root directory, because it is easier to for the download process. (it doesent show in the database as http://www.gtld.com/uploads/merlo.zipintead its just merlo.zip, can i change it?would this work? $query = "INSERT INTO `" . $_POST['options'] . "` (title, author, Image_file, File) VALUES ('$_POST[Title]', '$_POST[Author]', 'http://www.gtld.com/uploads/{$_FILES['file']['name']}','http://www.gtld.com/image_uploads/{$_FILES['file']['name']}')"; Thanks again, Link to comment Share on other sites More sharing options...
imrie Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks it worked, Link to comment Share on other sites More sharing options...
imrie Posted August 10, 2007 Author Share Posted August 10, 2007 eek, its not working, the image is not uploading to the folder. the zip file does.However, the url of the image file goes into the database.code: <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ $success = true; $type = $_FILES['file']['type'];$Title=$_POST['Title']; $Author=$_POST['Author']; if ($type == "image/gif" || $type == "image/jpeg" || $type == "image/bmp") { //upload image if ($_FILES['file1']['size'] > 500000) { echo "Error: The image is too large!"; } else { move_uploaded_file($_FILES["file1"]["tmp_name"],"image_uploads/" . $_FILES["file1"]["name"]); if (file_exists("PATH" . $_FILES["file1"]["name"])) { echo $_FILES["file1"]["name"] . " already exists. "; } } } else if ($type == "application/rar" || $type == "application/zip" || $type = "application/x-zip-compressed") { //Upload file if ($_FILES['file']['size'] > 150000000) { echo "Error: The file is too large!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); if (file_exists("PATH" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } } } else { //Invalid file type $success = false; echo "Error: File type $type not valid"; } if ($success) { mysql_connect("","imrieimag", "");mysql_select_db("imrieimag");$query = "INSERT INTO `" . $_POST['options'] . "` (title, author, Image_file, File) VALUES ('$_POST[Title]', '$_POST[Author]', 'http://www.mysimtractor.com/image_uploads/{$_FILES['file1']['name']}','http://www.mysimtractor.com/uploads/{$_FILES['file']['name']}')"; mysql_query($query); }}?> Link to comment Share on other sites More sharing options...
Synook Posted August 11, 2007 Share Posted August 11, 2007 The problem is here if ($type == "image/gif" || $type == "image/jpeg" || $type == "image/bmp") { The script is still checking the type of the zip when it tries to upload the image. Replace is with something like $image_type = $_FILES['file1']['type'];if ($image_type == "image/gif" || $image_type == "image/jpeg" || $image_type == "image/bmp") { Link to comment Share on other sites More sharing options...
imrie Posted August 11, 2007 Author Share Posted August 11, 2007 Now the zip isint going being uploaded and nothing is going into the database. Link to comment Share on other sites More sharing options...
imrie Posted August 11, 2007 Author Share Posted August 11, 2007 I think it seems to either-or sometimes a .zip uploads and the other time its an image, it varies. But its not going into the database.Could be that i need to also define an image along with "file1" on the insert process. Link to comment Share on other sites More sharing options...
Synook Posted August 11, 2007 Share Posted August 11, 2007 No don't worry - just change } else if ($type == "application/rar" || $type == "application/zip" || $type = "application/x-zip-compressed") { to } else { //Invalid file type $success = false; echo "Error: Image file type $image_type not valid"; }if ($type == "application/rar" || $type == "application/zip" || $type = "application/x-zip-compressed") { Link to comment Share on other sites More sharing options...
imrie Posted August 11, 2007 Author Share Posted August 11, 2007 Thanks, one more thing.The File (.zip) goes into the database as http://www.mysimtractor.c. whereas the image is corerect: http://www.mysimtractor.com/image_uploads/image.bmp.Coding: <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ $success = true; $type = $_FILES['file']['type'];$Title=$_POST['Title']; $Author=$_POST['Author']; $image_type = $_FILES['file1']['type'];if ($image_type == "image/gif" || $image_type == "image/jpeg" || $image_type == "image/bmp") { //upload image if ($_FILES['file1']['size'] > 500000) { echo "Error: The image is too large!"; } else { move_uploaded_file($_FILES["file1"]["tmp_name"],"image_uploads/" . $_FILES["file1"]["name"]); if (file_exists("PATH" . $_FILES["file1"]["name"])) { echo $_FILES["file1"]["name"] . " already exists. "; } } } else { //Invalid file type $success = false; echo "Error: Image file type $image_type not valid"; }if ($type == "application/rar" || $type == "application/zip" || $type = "application/x-zip-compressed") { //Upload file if ($_FILES['file']['size'] > 150000000) { echo "Error: The file is too large!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"uploads/" . $_FILES["file"]["name"]); if (file_exists("PATH" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } } } else { //Invalid file type $success = false; echo "Error: File type $type not valid"; } if ($success) { mysql_connect("","imrieimag", "");mysql_select_db("imrieimag");$query = "INSERT INTO `" . $_POST['options'] . "` (title, author, Image_file, File) VALUES ('$_POST[Title]', '$_POST[Author]', 'http://www.mysimtractor.com/image_uploads/{$_FILES['file1']['name']}','http://www.mysimtractor.com/uploads/{$_FILES['file']['name']}')"; mysql_query($query); }}?> Link to comment Share on other sites More sharing options...
Synook Posted August 12, 2007 Share Posted August 12, 2007 When you set up you mySQL table, you may have given a too short length to the `File` field, as in VARCHAR(25). Link to comment Share on other sites More sharing options...
imrie Posted August 12, 2007 Author Share Posted August 12, 2007 0 how do i edit this? Link to comment Share on other sites More sharing options...
Synook Posted August 12, 2007 Share Posted August 12, 2007 Use phpMyAdmin, or ALTER TABLE table CHANGE File File VARCHAR(120) NOT NULL Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.