Jump to content

file upload script problem...


rsammy

Recommended Posts

hi,

 

i am trying to upload a file (any file) to a server (in this case, my local machine). i have created two php files (named main.php and upload.php). i launch main.php and it lets me browse for a file. i select a file, say abc.txt and then click on the Upload button.

 

at this point, what it does is, throw up a dialog box asking me if I want to open or save this file (upload.php) with Open, Save and Cancel buttons. When I click Open. it opens upload.php file in notepad/editpad. if i click Save, it lets me choose a folder to save this file for me.

 

however, this is not what i want it to do. i would like it to save the file i chose initially (abc.txt) in a locaion i choose and i should not be worried about my upload.php script file.

 

here is the code in my upload.php file:

<?php
alert "HERE";
//$web = 'c:/wamp/uploads/'; // path under webroot
$web = 'c:/wamp/www/'; // path under webroot
$destination =$_FILES['updfile']['name'];


if ($_POST['btn'] == "Upload")
{
	if(empty($_POST['userid'])) //Check for User ID
	{
		echo "User ID should not be Blank!!<br/>";
	}
	else
	{
		$uploaddir = $web."".$_POST['userid'];
		if(!is_dir($uploaddir)) // Check for existing directory else create new dir for the user
		{
			mkdir($uploaddir);
		}

	$uploadfile = $uploaddir."/".basename($destination);

    	if(isset($_FILES['updfile']['tmp_name']))
    	{
		if(($_FILES['updfile']['error'] == 0) && !empty($_FILES['updfile']) && !file_exists($uploadfile))
    		{
   			if(move_uploaded_file($_FILES['updfile']['tmp_name'],$uploadfile))
   			{
	  			echo "File Uploaded Successfully!!!<br/>";
			}
		}
    		else
       		echo "File Upload Failed";
	}
	}
}
?>

<form>
<table border ="0">
<tr>
<td> List of Filenames : </td>
<td> <select name="filenames" id="fields" >
<?php

if ($dh = opendir($uploaddir))
{
	while (($file = readdir($dh)) !== false)
	{
		$options = NULL;
		$options.= '<option value="'.$file.'">'.$file.'</option>'."\n";
		echo $options;
	}
	closedir($dh);
}
?>
</select>
</td>
</tr>
</form>

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.