file upload

I am trying to set up a form to upload pdf files to my site. It will be in a password protected folder so I don't need security, but it keeps telling me the file has been uploaded, without the file name, and the file has not actually been uploaded.
upload_files.php
<?php 
$target = "docs/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}
?> 
 
-------------------------------------------------------------
My form
 
<form enctype="multipart/form-data" action="upload_files.php" method="POST">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file 
<input name="uploaded" type="file" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>

Open in new window

sendhelpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
I'll post my standard upload script in a moment.  It covers the waterfront!
0
Ray PaseurCommented:
Please let me know if you have any questions.  Best regards, ~Ray
<?php // RAY_upload_demo.php
 
// NAME OF THE DIRECTORY FOR UPLOADS
$uploads = 'uploads';
 
// UPLOAD ERRORS
$errors	= array(
	0=>"<span>Success!</span>",
	1=>"<span class=\"required\">The uploaded file exceeds the upload_max_filesize directive in php.ini</span>",
	2=>"<span class=\"required\">The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form</span>",
	3=>"<span class=\"required\">The uploaded file was only partially uploaded</span>",
	4=>"<span class=\"required\">No file was uploaded</span>",
	6=>"<span class=\"required\">Missing a temporary folder</span>",
	7=>"<span class=\"required\">Cannot write file to disk</span>"
);
 
// IF NO UPLOAD HAS HAPPENED, PUT UP THE FORM
if ( (empty($_GET['p'])) && (empty($_POST['MAX_FILE_SIZE'])) ) { ?>
 
	<h2>Welcome to File Upload Demo</h2>
	<!-- nb:enctype -->
	<form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["REQUEST_URI"]?>?p=1" method="POST">
	<!-- MAX_FILE_SIZE must precede the file input field -->
	<input type="hidden" name="MAX_FILE_SIZE" value="8192000" />
	<!-- Name of input element is userfile - determines name in $_FILES array -->
 
	Find the file and click the "Upload" button below.<br />
	File Name:&nbsp; <input name="userfile" type="file" size="80" /> &nbsp; <input type="submit" name="_submit" value="Upload" />
	</form>
<?php
 
	die();
 
} else {
// WE HAVE AN UPLOADED FILE - PUT IT SOMEWHERE SAFE
 
// DATE TIME STAMP BECOMES PART OF FILE NAME
	$filedate	= date('Ymd\THis');
 
// SYNTHESIZE A NEW FILE NAME (MAYBE USE THE CLIENT USER ID, IF ONE EXISTS)
	$f_type	= trim(strtolower(end(explode( '.', basename($_FILES['userfile']['name'] )))));
	$my_new_file	= getcwd() . '/' . $uploads . '/' . $filedate . '.'. $f_type;
	$my_file	=                  $uploads . '/' . $filedate . '.'. $f_type;
 
// MOVE THE FILE INTO THE DIRECTORY
	$error_code	= $_FILES["userfile"]["error"];
	$file_size	= number_format($_FILES["userfile"]["size"]);
 
// PAGE HEADER
	echo "<h2>File Upload Demo</h2>\n";
 
// CHECK UPLOAD ERROR CODE
	if ($error_code != 0) {
		$error_message = $errors[$error_code];
		echo "<p>Upload Error Code: $error_code: $error_message</p>\n";
		echo "<p><a href=\"$_SERVER[PHP_SELF]\">Try again?</a></p>\n";
		die();
	}
 
// REPORT STATUS OF UPLOAD
	if (move_uploaded_file($_FILES['userfile']['tmp_name'], $my_new_file)) {
		echo "<p>\n";
		echo "UPLOAD COMPLETE: \n";
		echo "$file_size bytes saved in $my_file.\n";
		echo "</p>\n";
		chmod ($my_new_file, 0755);
	} else {
		echo "<p>\n";
		echo "Merde! function move_uploaded_file() to $my_new_file failed\n";
		echo "</p>\n";
		die();
	}
}
 
// PROCESS THE INFORMATION IN THE UPLOADED FILE...
 
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sendhelpAuthor Commented:
You are awesome!
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Ray PaseurCommented:
sendhelp: Thanks for the points!  Best regards, ~Ray
0
whspiderCommented:
the code works perfectly fine for small files
But when I upload files of size around 25Mb
I get the following  error

Merde! function move_uploaded_file() to /home/travel/public_html/upload/upload/20091023T092253. failed
0
Ray PaseurCommented:
Check the file size in the script and also run phpinfo() and check for max post size, max file size, etc. in there.  Your uploads are getting throttled by the server or by the PHP settings.  Could be a lot of things wrong with file uploads of that size!
0
whspiderCommented:
I increased the max upload size.

A file of this size cannot be uploaded directly from forms ?
0
Ray PaseurCommented:
You should consider opening a question about this!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.