emediastudios Posted November 5, 2007 Share Posted November 5, 2007 I have this code that works good, just have to implement some filters. How would i change this code if i wanted to add 3 images instead of just the 1. I have input fields and fields in my database called photo1, phot02 and photo3. <?php require_once('../Connections/gcproperty.php'); ?> <?php //This is the directory where images will be saved $target = "../images/news/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $headline=$_POST['headline']; $link=$_POST['link']; $content=$_POST['content']; $photo1=($_FILES['photo'1]['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target)) { //Tells you if its all ok print "<meta http-equiv=\"refresh\" content=\"0;URL=news_added_successfully.php\">"; //Writes the information to the database mysql_query("INSERT INTO `news` VALUES ('$headline','$photo1','$content','$link')") ; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/ Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 i changed my code to this. <?php require_once('../Connections/p2w.php'); ?> <?php //This is the directory where images will be saved $target = "../news/"; $target = $target . basename( $_FILES['photo1']['name']); //This gets all the other information from the form $headline=$_POST['headline']; $contents=$_POST['contents']; $photo1=($_FILES['photo1']['name']); $photo2=($_FILES['photo2']['name']); $photo3=($_FILES['photo3']['name']); $title1=$_POST['title1']; $title2=$_POST['title2']; $title3=$_POST['title3']; $link=$_POST['link']; //Writes the photo to the server if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target)) { //Tells you if its all ok echo "Success."; //Writes the information to the database mysql_query("INSERT INTO `news` VALUES (NULL,'$headline','$contents','$photo1','$photo2','$photo3','$title1','$title2','$title3','$link')") ; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Only uploads the one file, i know why but how i get it to do the 3? Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385289 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 loop your move upload function Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385290 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 Im a biginner in php could you please explain how i do that. sorry Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385305 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; if(move_uploaded_file($_FILES[$photo]['tmp_name'], $target)){ ect....... } } Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385310 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 Thanks for your help. I did as you said and get this error Parse error: syntax error, unexpected $end in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 39 My code looks like this now <?php require_once('../Connections/p2w.php'); ?> <?php //This is the directory where images will be saved $target = "../news/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $headline=$_POST['headline']; $contents=$_POST['contents']; $photo1=($_FILES['photo1']['name']); $photo2=($_FILES['photo2']['name']); $photo3=($_FILES['photo3']['name']); $title1=$_POST['title1']; $title2=$_POST['title2']; $title3=$_POST['title3']; $link=$_POST['link']; //Writes the photo to the server for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; if(move_uploaded_file($_FILES[$photo]['tmp_name'], $target)){ //Tells you if its all ok echo "Success."; //Writes the information to the database mysql_query("INSERT INTO `news` VALUES (NULL,'$headline','$contents','$photo1','$photo2','$photo3','$title1','$title2','$title3','$link')") ; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385316 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 <?php require_once('../Connections/p2w.php'); //This is the directory where images will be saved $target = "../news/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $headline=$_POST['headline']; $contents=$_POST['contents']; $photo1=($_FILES['photo1']['name']); $photo2=($_FILES['photo2']['name']); $photo3=($_FILES['photo3']['name']); $title1=$_POST['title1']; $title2=$_POST['title2']; $title3=$_POST['title3']; $link=$_POST['link']; //Writes the photo to the server for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; if(move_uploaded_file($_FILES[$photo]['tmp_name'], $target)){ //Tells you if its all ok echo "Success."; //Writes the information to the database mysql_query("INSERT INTO `news` VALUES (NULL,'$headline','$contents','$photo1','$photo2','$photo3','$title1','$title2','$title3','$link')") ; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } ?> you missed } Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385326 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 I pasted your code over mine and now i get this. Warning: move_uploaded_file(../news/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 18 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\TEMP\php1CB6.tmp' to '../news/' in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 18 Sorry, there was a problem uploading your file. Warning: move_uploaded_file(../news/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 18 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\TEMP\php1CC7.tmp' to '../news/' in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 18 Sorry, there was a problem uploading your file. Warning: move_uploaded_file(../news/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 18 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\TEMP\php1CC8.tmp' to '../news/' in C:\Program Files\Apache Group\Apache2\htdocs\Prepare2win\admin\upload_news.php on line 18 Sorry, there was a problem uploading your file. ??? Thanks for your help Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385329 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 check your folder or dir mod bu sure its writable (777) Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385333 Share on other sites More sharing options...
Demonic Posted November 6, 2007 Share Posted November 6, 2007 check your folder or dir mod bu sure its writable (777) lol you don't need to chmod files on windows.. Your server might now allow that function, or its disabled. Never seen that happen on a windows server to be honest. Check if the directory your moving it to exists. Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385335 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 The directory exists. and i have other upload files that work. this is strange. Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385340 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 check your folder or dir mod bu sure its writable (777) lol you don't need to chmod files on windows.. Your server might now allow that function, or its disabled. Never seen that happen on a windows server to be honest. Check if the directory your moving it to exists. I have this code that works good, just have to implement some filters. How would i change this code if i wanted to add 3 images instead of just the 1. I have input fields and fields in my database called photo1, phot02 and photo3. Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385343 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 Changed this a little as i have this code in another site <?php for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; if(move_uploaded_file($_FILES[$photo . $x]['tmp_name'], $target)){ ?> Gave me this error Sorry, there was a problem uploading your file.Sorry, there was a problem uploading your file.Sorry, there was a problem uploading your file. could there b a problem here $target = $target . basename( $_FILES['photo']['name']); Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385345 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 i should have seen that lol put that inside the loop for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; $target = $target . basename( $_FILES[$photo]['name']); if(move_uploaded_file($_FILES[$photo]['tmp_name'], $target)){ //Tells you if its all ok echo "Success."; //Writes the information to the database mysql_query("INSERT INTO `news` VALUES (NULL,'$headline','$contents','$photo1','$photo2','$photo3','$title1','$title2','$title3','$link')") ; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385349 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 i should have seen that lol put that inside the loop for ($x=1;$x<=3;$x++){ $photo ='photo'.$x; $target = $target . basename( $_FILES[$photo]['name']); if(move_uploaded_file($_FILES[$photo]['tmp_name'], $target)){ //Tells you if its all ok echo "Success."; //Writes the information to the database mysql_query("INSERT INTO `news` VALUES (NULL,'$headline','$contents','$photo1','$photo2','$photo3','$title1','$title2','$title3','$link')") ; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } Works Thanks heaps, Im so gratefull Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385355 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385356 Share on other sites More sharing options...
emediastudios Posted November 6, 2007 Author Share Posted November 6, 2007 Found a problem. It inserts the record into sql 3 times. Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385359 Share on other sites More sharing options...
teng84 Posted November 6, 2007 Share Posted November 6, 2007 what do you expect its inside the loop? just move it outside if you want it to insert once Link to comment https://forums.phpfreaks.com/topic/76126-solved-upload-more-images/#findComment-385369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.