dtjester Posted April 23, 2008 Share Posted April 23, 2008 Hi, I am pretty new to PHP and I am haveing trouble with this script I wrote. The object is to take form data and two images, upload the 2 images it 2 different dir. and take the paths to those images, and the other form data and insert into my MySQL table. Everything works, except I cannot find the images. The paths to the images are correct and they are being stored in the table, but the images aren't there. I don't get it. Also, I am trying to add the date added to the table, but it just gets entered as 0000-00-00 in the table. Is my syntax correct? Below is my script: if ((($_FILES["img_thumb"]["type"] == "image/gif") || ($_FILES["img_thumb"]["type"] == "image/jpeg") || ($_FILES["img_thumb"]["type"] == "image/pjpeg")) && ($_FILES["img_thumb"]["size"] < 200000)) { if ($_FILES['img_thumb']['error'] > 0) { echo "Error: " . $_FILES['img_thumb']['error'] . "<br />"; } else { echo "File was uploaded successfully!"; } if (file_exists("images/favors/thumbs/" . $_FILES['img_thumb']['name'])) { echo $_FILES['img_thumb']['name'] . " already exists. "; } else { move_uploaded_file($_FILES['img_thumb']['tmp_name'], "images/favors/thumbs/" . $_FILES['img_thumb']['name']); } } else { echo "Invalid file"; } $thumb_path = "images/favors/thumbs/" . $_FILES['img_thumb']['name']; //*********end thumbnail upload************ //Upload Fullsize Image if ((($_FILES["img_full"]["type"] == "image/gif") || ($_FILES["img_full"]["type"] == "image/jpeg") || ($_FILES["img_full"]["type"] == "image/pjpeg")) && ($_FILES["img_full"]["size"] < 200000)) { if ($_FILES['img_full']['error'] > 0) { echo "Error: " . $_FILES['img_full']['error'] . "<br />"; } else { echo "File was uploaded successfully!"; } if (file_exists("images/favors/" . $_FILES['img_full']['name'])) { echo $_FILES['img_full']['name'] . " already exists. "; } else { move_uploaded_file($_FILES['img_full']['tmp_name'], "images/favors/" . $_FILES['img_full']['name']); } } else { echo "Invalid file"; } $full_path = "images/favors/" . $_FILES['img_full']['name']; //**************End upload fullsize image************* //add info to database $db_name = '*****'; $hostname = '*****'; $username = '*****'; $password = '*****'; $tablename = '*****'; $connection = @mysql_connect($hostname, $username, $password) or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "INSERT INTO $tablename VALUES ('$_POST[id]', '$_POST[name]', '$_POST[desc]', '$_POST[cost]', '$_POST[category]', '$_POST[style]', 'NOW()', '$thumb_path', '$full_path')"; $result = mysql_query($sql,$connection) or die(mysql_error()); if ($result) { $msg = "New Favor has been added!"; } echo $msg; ?> Link to comment https://forums.phpfreaks.com/topic/102461-solved-upload-2-images-with-one-form/ Share on other sites More sharing options...
mrdamien Posted April 23, 2008 Share Posted April 23, 2008 Try using basename() for the move_uploaded_file AND use NOW(), not 'NOW()' the later is a string and won't get evaluated as a function. if ((($_FILES["img_thumb"]["type"] == "image/gif") || ($_FILES["img_thumb"]["type"] == "image/jpeg") || ($_FILES["img_thumb"]["type"] == "image/pjpeg")) && ($_FILES["img_thumb"]["size"] < 200000)) { if ($_FILES['img_thumb']['error'] > 0) { echo "Error: " . $_FILES['img_thumb']['error'] . "<br />"; } else { echo "File was uploaded successfully!"; } if (file_exists("images/favors/thumbs/" . $_FILES['img_thumb']['name'])) { echo $_FILES['img_thumb']['name'] . " already exists. "; } else { move_uploaded_file($_FILES['img_thumb']['tmp_name'], "images/favors/thumbs/" . basename($_FILES['img_thumb']['name'])); } } else { echo "Invalid file"; } $thumb_path = "images/favors/thumbs/" . $_FILES['img_thumb']['name']; //*********end thumbnail upload************ //Upload Fullsize Image if ((($_FILES["img_full"]["type"] == "image/gif") || ($_FILES["img_full"]["type"] == "image/jpeg") || ($_FILES["img_full"]["type"] == "image/pjpeg")) && ($_FILES["img_full"]["size"] < 200000)) { if ($_FILES['img_full']['error'] > 0) { echo "Error: " . $_FILES['img_full']['error'] . "<br />"; } else { echo "File was uploaded successfully!"; } if (file_exists("images/favors/" . $_FILES['img_full']['name'])) { echo $_FILES['img_full']['name'] . " already exists. "; } else { move_uploaded_file($_FILES['img_full']['tmp_name'], "images/favors/" . basename($_FILES['img_full']['name'])); } } else { echo "Invalid file"; } $full_path = "images/favors/" . $_FILES['img_full']['name']; //**************End upload fullsize image************* //add info to database $db_name = '*****'; $hostname = '*****'; $username = '*****'; $password = '*****'; $tablename = '*****'; $connection = @mysql_connect($hostname, $username, $password) or die(mysql_error()); $db = @mysql_select_db($db_name, $connection) or die(mysql_error()); $sql = "INSERT INTO $tablename VALUES ('$_POST[id]', '$_POST[name]', '$_POST[desc]', '$_POST[cost]', '$_POST[category]', '$_POST[style]', NOW(), '$thumb_path', '$full_path')"; $result = mysql_query($sql,$connection) or die(mysql_error()); if ($result) { $msg = "New Favor has been added!"; } echo $msg; ?> Link to comment https://forums.phpfreaks.com/topic/102461-solved-upload-2-images-with-one-form/#findComment-524690 Share on other sites More sharing options...
dtjester Posted April 23, 2008 Author Share Posted April 23, 2008 Changing the 'NOW()' to NOW() fixed that part, but still no luck on the images being there. Link to comment https://forums.phpfreaks.com/topic/102461-solved-upload-2-images-with-one-form/#findComment-524693 Share on other sites More sharing options...
dtjester Posted April 23, 2008 Author Share Posted April 23, 2008 I am using godaddy to host my sites. The one I am trying to use this script on is Windows hosting. I moved it to another site that uses linux hosting and it worked fine. I wonder if it is a PHP configuration issue? Link to comment https://forums.phpfreaks.com/topic/102461-solved-upload-2-images-with-one-form/#findComment-524695 Share on other sites More sharing options...
NikkiLoveGod Posted April 23, 2008 Share Posted April 23, 2008 I'd say its a rights issue. You dont have the sufficient rights to mvoe the file into the specified folder. You might want to consult your service provider to check that the server has the rights for that folder. ( that is, if you cant check your self ) -Nikki Link to comment https://forums.phpfreaks.com/topic/102461-solved-upload-2-images-with-one-form/#findComment-524714 Share on other sites More sharing options...
dtjester Posted April 23, 2008 Author Share Posted April 23, 2008 Thanks for the input everyone. I decided that I am going to switch to Linux hosting and solve all my problems. Consider this solved! Link to comment https://forums.phpfreaks.com/topic/102461-solved-upload-2-images-with-one-form/#findComment-525390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.