Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP form action

Status
Not open for further replies.

bobbiedigital

Programmer
Sep 18, 2004
83
AU
Hi i would like to know if its possible in php to post html form info to more than one php file??

cheers bobbie
 
What do you want to do? Maybe there is a different way of doing it.

Ken
 
You could include the second php file in the first. That would make it go through both of them. I agree with Ken, there is definitely a better way of doing this.
 
HI thanks for the reply this is what i am trying to do

i have created a html file called insert_news.html, this file uses, <form action="upload_article.php" method="post" enctype="multipart/form-data">

upload_article.php includes an sql statement to an sql database, also a call to another php file called news.php which includes a news class and a function called upload(), this upload function takes is supposed to take the posted data from the html (<- this is what i am not sure about), i then create a unique name for the file and try to upload it using (HTTP_POST_FILES['article_picture'][tmp_name], $filename); but it keeps coming up with an error saying that ['artile_picture'] is not an indexed variable. i know it reaches the upload function as the picture name inserted into the sql database is a unique and different to the origonal.


eheheh does that make sense??? do you want me to upload some code???


cheers bobbie

cheers b
 
First read the part of the manual that deals with uploading files
You want to use the $_FILES superglobal array.

By the time your PHP script is executed, the file has already been uploaded to a temporary location and can be referenced with "$_FILES['article_picture']['tmp_name']". You then want to use the move_uploaded_file() function to move it to where you want it.

If you can't include the logic from the second script in the first, you can use Sessions to pass the values you need between the scripts.

If you post some of your code, it might be helpful to us to understand what you are trying to do.

Ken
 
sorry for the late reply here is my code i hope it helps


insert_news.html

<form action="upload_article.php" method="post" enctype="multipart/form-data">

upload_article.php

$filename= $_POST['article_picture'];

//create new instance of news class and call upload function
$upload_picture = new news();
$upload_picture->upload($filename);
$filename2 = $upload_picture->filename;


news.php

class news {
upload function connects uploads to picture directory on server
*/

function upload($filename){
// define the base image dir
$base_img_dir = "./pictures/";

// generate unique id for use in filename
$uniq = uniqid("");

// new file name
$jpg =".jpg";

$this->filename = $base_img_dir.$uniq.$jpg;



// move uploaded file to destination
if (move_uploaded_file($HTTP_POST_FILES['article_picture']['tmp_name'], $filename)) {
print "Thank you for your submission of $filename.";
return $filename;
}else {

# If the file couldn't be moved, we tell the user:
print "An error occurred during your submission.";
//echo ($filename);
return $filename;
// exit();
}
} // end function upload

} //end class news





the news class also includes a function which connects to the database but that works fine, the upload_article.php contains the sql statement which inserts all details into the database, this also works fine.

I appreciate the help cheers

bobbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top