Jump to content

file upload blues!


boo_lolly

Recommended Posts

Hey guys, it's been a while since I've coded in PHP but this is definitely more difficult than it should be. I've got just a small upload form and script, but it's got problems and I don't know where they might be.

 

form

	<form action="get_file.php" method="post" enctype="multipart/form-data">
	Select File: <input type="file" name="uploadFile">
	<input type="submit" value="Upload Spreadsheet">
	</form>

 

script

<?php
print "<pre>";
print $_FILES;
print "</pre>";
?>

 

and it prints:

Array

 

that's it. I get nothing. At first I had this upload script renaming it and moving the file to a certain location, but it wasn't working. So I cut it all out and I find out that the file wasn't being uploaded at all. So what could be the problem here?

Link to comment
https://forums.phpfreaks.com/topic/117270-file-upload-blues/
Share on other sites

Alright guys. I've got some other stuff going on with this. Last night this script was working, but I had to make a small change this morning. Last night the script was uploading and I found out it was due to directory permissions. The directory of both 'get_file.php' and the .html file I was uploading didn't have write permissions, so I changed that. Then I decided that I didn't want that, I wanted to have another directory inside it called 'public' and change the permissions on THAT to have write permissions, but not the parent directory that I had been uploading it into earlier, successfully. So I make those changes, and now it doesn't work! Here's what I've got.

 

get_file.php

<?php
$filename = basename($_FILES['uploaded_file']['name']);
//print $filename ."<br />";
$ext = substr($filename, strrpos($filename, '.'));
//print $ext ."<br />";
if ($ext != ".htm" && $ext != ".html") {
	print "Invalid filetype. Must be .htm or .html file.";
} else {
	$newname = dirname(__FILE__) ."/public/load_excel". $ext ."<br />";
	print $newname;
	if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $newname)) {
		print "It's done! The file has been saved as:
		<a href=\"public/". basename($newname) ."\">". basename($newname) ."</a>";
	} else {
		print "Error: A problem occurred during file upload!";
	}
}
?>

 

and it prints:

/home/httpd/vhosts/mydomain.com/httpdocs/loads/public/load_excel.html
Error: A problem occurred during file upload!

 

What's going on here? Why won't it work? The 'loads' directory does not have write permissions (755) but public directory does (777). Why would changing one small thing like that break it entirely? Does anyone see what I'm not seeing?

Link to comment
https://forums.phpfreaks.com/topic/117270-file-upload-blues/#findComment-603625
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.