Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload Form Temp File

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
I have a file upload form that WAS working but now all of a sudden it is giving an error that it is unable to move the temp file. Looking at the temp tile name supplied in one case, it is [bold]php1NsZFZ[/bold] but the files in the temp folder have a dot: [bold]php.1NsZFZ[/bold]. Nothing was changed in the code from when it was working so I am at a loss. The files are being retrieved with:

Code:
$EntryType = $_SESSION['ProcessType'];

foreach ($Files["error"] as $key => $error):
	if ($error == UPLOAD_ERR_OK):
		$tmp_name = $Files["tmp_name"][$key];
		$Filename = $Files["name"][$key];
		$Size = ($Files["size"][$key]);
		$FileTime = filemtime($Files["tmp_name"][$key]);
		$Filename = trim(str_replace(" ", "_", $Filename));
		$Pieces = explode("_", $Filename, 2);
		$Subfolder = $Pieces[0];
		$oldumask = umask(0);
		if (!is_dir("$UploadPath/$EntryType")) mkdir("$UploadPath/$EntryType", 01777);
		umask($oldumask);
		$oldumask = umask(0);
		if (!is_dir("$UploadPath/$EntryType/$Subfolder")) mkdir("$UploadPath/$EntryType/$Subfolder", 01777);
		umask($oldumask);
		$Folder = "$UploadPath/$EntryType/$Subfolder";


etc.

Any ideas?
 
windows computers may require an 8.3 filename. a name as you had it originally is essentially a .0 file name, therefore acceptable. the latter name is essentially an X.6 filename, which may well not be acceptable.
 
That is not a limitation here even on my Windows development platform but in this case the development is on Linux. The odd thing is that it WAS working just fine and now it suddenly isn't so I guess I'll have to look up the basics of file submissions to see what I am doing wrong. In this case it is to handle multiple files. In any event, the temp file name created itself and I had no choice in the matter.
 
I was not aware that php stored uploaded temp files with an interstitial dot. It does not on any of my builds.

please post the exact error you get on move_uploaded_file(). it should be being raised as an E_WARNING

 
I found the problem - the lines in red below should not be there.

Code:
$EntryType = $_SESSION['ProcessType'];

foreach ($Files["error"] as $key => $error):
	if ($error == UPLOAD_ERR_OK):
		$tmp_name = $Files["tmp_name"][$key];
		$Filename = $Files["name"][$key];
		$Size = ($Files["size"][$key]);
		$FileTime = filemtime($Files["tmp_name"][$key]);
		$Filename = trim(str_replace(" ", "_", $Filename));
		$Pieces = explode("_", $Filename, 2);
		$Subfolder = $Pieces[0];
		$oldumask = umask(0);
		if (!is_dir("$UploadPath/$EntryType")) mkdir("$UploadPath/$EntryType", 01777);
		[COLOR=red]umask($oldumask);
		$oldumask = umask(0);[/color]
		if (!is_dir("$UploadPath/$EntryType/$Subfolder")) mkdir("$UploadPath/$EntryType/$Subfolder", 01777);
		umask($oldumask);
		$Folder = "$UploadPath/$EntryType/$Subfolder";
 
The first line should not. But then the error notice should have made it clear the problem was permissions based and you wouldn't have needed to post in the first place.

If you take both lines out also delete the next call to umask() otherwise it might reduce the mask and cause unexpected problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top