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
Share on other sites

ok PHPers I did a little research and found out the issue. Apparently I'm only allowed to upload .jpg image files and they can only be 350kb in size. I want to upload .html and .htm files. Where is this regulation handled? In the php.ini file?

Link to comment
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
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.