Jump to content

Uploading to the server


11Tami

Recommended Posts

Hello I'm trying to upload a file to the server when a submit button is pushed. For instance,

 

 

<?php

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" /><HTML>

<TITLE>Uploading a file</TITLE>

</HEAD>

<BODY>

<FORM ENCTYPE="multipart/form-data" NAME=MyForm ACTION=submit.php METHOD="POST">

<INPUT TYPE="hidden" NAME="command" VALUE="1">

<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000">

<INPUT NAME="MyFile" TYPE="File">

<INPUT NAME="submit" VALUE="Upload" TYPE="submit">

</FORM>

<?php

$link = mysql_connect('database address', 'databasename', 'password');

if (!$link) {

die('Not connected : ' . mysql_error());

}

 

$db_selected = mysql_select_db('databasename', $link);

if (!$db_selected) {

die ('Can\'t use database : ' . mysql_error());

}

 

$query = "SELECT softwarename FROM addsoftware WHERE `id` = '46'";

 

$result = mysql_query($query) or die(mysql_error()."

".$query);

 

while ($row = mysql_fetch_array($result))

 

{

echo <span>$row[softwarename]</span>";

}

 

?>

<BR><BR>

</CENTER>

</BODY>

</HTML>

<?php 

$DestinationDir = "/uploadedfiles/";

$DestinationFile = $DestinationDir . $_FILES['MyFile']['name'];

If (move_uploaded_file($_FILES['MyFile']['tmp_name'], $DestinationFile)) {

Echo "File uploaded successfully.";

}Else{

Echo $_FILES['MyFile']['error'];

?>

 

But I don't know how to upload the whole file instead of only whats in the submit form. The whole above example I found online says its supposed to upload a whole file yet this: $_FILES['MyFile']['name'];  --is only asking for whats in the input of form of the page, not the whole page. Need help. Please let me know how to do this, thank you very much.

Link to comment
https://forums.phpfreaks.com/topic/58865-uploading-to-the-server/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.