Jump to content

[SOLVED] upload file on php self post


bradkenyon

Recommended Posts

i am trying to upload a file to a directory on my server, then post the filename into the database for future reference.

 

for some reason the file won't upload, nor will it post the filename into the db.

 

i've done this before, but it was done before by having the action="" within the form tag pointing to another page w/ the appropriate code for getting the form results, but i want it to do a php self post, but that is the problem i'm running into w/ getting that file to upload.

 

here is the code.

 

any help is appreciated, thanks!

 

if(!$_POST)
{ ?>
<div class="details">
	<form enctype="multipart/form-data" method="post" action="?mode=add"> <?
		print '<h3>Headline/Subject</h3>';
		print '<input type="text" name="subj" size="60">';

		print '<h3>Body</h3>';
		print '<textarea name="body" cols="70" rows="14"></textarea>';

		/*
		print '<h3>Image URL</h3>';
		print '<input type="text" name="imgurl" size="80">';
		*/

		print '<h3>More Info URL</h3>';
		print '<input type="text" name="moreurl" size="80">';

		print '<h3>Date</h3>';
		print '<input type="text" name="tstamp" value="'.date("Y-m-d H:i:s",time()).'" size="20">';

		print '<h3>Image Upload</h3>
				<input type="file" name="uploaded"> <small>(optional)</small><p>';

		print	'<input type="Submit" value="Submit" name="Submit">
				<a href="/cms/">Cancel</a>
	</form>';
}
else
{

//$id=$HTTP_POST_VARS['id'];
$subj=addslashes($HTTP_POST_VARS['subj']);
$body=addslashes(htmlspecialchars($HTTP_POST_VARS['body']));
//$imgurl=$HTTP_POST_VARS['uploaded'];
$moreurl=$HTTP_POST_VARS['moreurl'];
$tstamp=$HTTP_POST_VARS['tstamp'];
$filename=$_FILES['uploaded']['name'];

if(!$filename == '')
{
	$target = "/web/images/news/"; 
	$target = $target . basename( $_FILES['uploaded']['name']);
	$ok=1;

	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
	{
		//echo "The file ".basename( $_FILES['uploaded']['name'])." has been uploaded";
	} 
	else 
	{
		echo "Sorry, there was a problem uploading your file.";
	}
}

mysql_query("INSERT INTO news (subj, body, imgurl, moreurl, tstamp) VALUES('$subj', '$body', '$filename', '$moreurl', '$tstamp')")
or die(mysql_error());  
include('newslist.php');
}
?>

 

 

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.