Jump to content

[SOLVED] Upload More images


emediastudios

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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 :);):D;D

Thanks heaps, Im so gratefull

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.