Jump to content

Recommended Posts

Hi there

 

i have used this script before in a slightly different way, but i can seem to get it to work this time, it keeps giving me my error message that the file could not be uploaded.  i have changed the form method from post to get.  is this allowed when trying to upload files??

 

all other information is entered into the database correclty, the file location is not though.

 

below is my code, any help would be muchly appreciated:

 

code to check the action of the page then run the correct case, code to upload file is here

 

<?

include('db_connection/db_connection.php');

include('code.php');

 

$id = $_GET['id'];

$type = $_GET['type'];

$title = $_GET['title'];

$author = $_GET['author'];

$text = addslashes($_GET['textfield']);

 

switch($type) {

case "view":

retrieve_full_news($id);

break;

case"edit":

news_form($id, $type);

break;

case"delete":

delete_news_item($id);

admin_list_news_items();

break;

case"update":

submitted_edited_news($id, $title, $author, $text);

admin_list_news_items();

break;

case"new":

news_form('0', $type);

break;

case"add_new":

$target_path = "www/test_site/news_images/";

$target_path = $target_path . basename( $_FILES['logo']['name']);

$target_path = addslashes($target_path);

 

if(move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)) {

echo "The file ".  basename( $_FILES['logo']['name']).

" has been uploaded";

} else{

echo "There was an error uploading the file, please try again!";

}

 

enter_news($title, $author, $text, $target_path);

admin_list_news_items();

break;

default:

admin_list_news_items();

}

?>

 

 

code for form:

 

function news_form($passed_id, $passed_type)

{

$sql = "SELECT * FROM news WHERE id = '$passed_id'";

$run = mysql_query($sql) or die(mysql_error());

$nt = mysql_fetch_array($run);

 

if($passed_type == 'new')

{

$new_type = 'add_new';

}else

{

$new_type = 'update';

}

 

echo "

<form name='form1' method='get' action='".$_SERVER['PHP_SELF']."' ENCTYPE='multipart/form-data'>

<input name='type' type='hidden' value='".$new_type."'>

<input name='id' type='hidden' value='".$passed_id."'>

<input type='hidden' name='MAX_FILE_SIZE' value='25000'>

<p>Title:

<input type='text' name='title' value='".$nt['title']."'>

</p>

<p>Author:

<input type='text' name='author' value='".$nt['author']."'>

</p>

<p>Date:".$nt['date']."</p>

<p>Text:

<textarea name='textfield' cols='60' rows='10'>".$nt['text']."</textarea>

</p>

<p>Image:        <input name='file' type='file' size='30' >

</p>

<p>

<input type='submit' name='Submit' value='Submit'>

</p>

</form>

";

 

}

 

is there maybe a cleaner way of doing this?

Link to comment
https://forums.phpfreaks.com/topic/51145-upload-image-script-is-not-uploading/
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.