File Uploads

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SL-Cowsrule
Forum Newbie
Posts: 13
Joined: Sat Oct 12, 2002 5:08 pm

File Uploads

Post by SL-Cowsrule »

I am using the following code:

config.php

Code: Select all

<?php
<?
$absolute_path = "/hsphere/local/home/twatters/gwatters.com/ta2/Uploads"; //upload path
$size_limit = "no"; //use limit size
$limit_size = "20000000"; //limit size
$limit_ext = "yes"; //limit the file type uploads
$ext_count = "6"; //number of types allowed
$extensions = array(".gif", ".jpg", ".jpeg", ".png", ".txt", ".doc"); //allowed file extensions
?>
?>
upload.php

Code: Select all

<?php
	require ("config.php");
	$endresult = "<font size="2">File Was Uploaded</font>";
	if ($file_name == "") {
		$endresult = "<font size="2">No file selected</font>";
	}else{
	if(file_exists("$absolute_path/$file_name")) {
			$endresult = "<font size="2">File Already Existed</font>";
	} else {
	if (($size_limit == "yes") && ($limit_size < $file_size)) {
		$endresult = "<font size="2">File was to big</font>";
	} else {
		$ext = strrchr($file_name,'.');
	if (($limit_ext == "yes") && (!in_array($ext,$extensions))) {
		$endresult = "<font size="2">File is wrong type</font>";
	}else{
		copy($file, "$absolute_path/$file_name");
	}
?>
It returns the error:
Warning: Unable to create '/Uploads/BnetLog.txt': No such file or directory in /hsphere/local/home/twatters/gwatters.com/ta2/upload.php on line 92

Line 92 is:

Code: Select all

<?php
		copy($file, "$absolute_path/$file_name");
?>
Thanks,
CoW

P.S. The permissions for the folder are set to be able to write to it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

P.S. The permissions for the folder are set to be able to write to it.
To whom this has been granted?
Does php share you opinion?

Code: Select all

is_writable($absolute_path) or die($absolute_path.' :permission denied');
ssand
Forum Commoner
Posts: 72
Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa

Re: File Uploads

Post by ssand »

It returns the error:
Warning: Unable to create '/Uploads/BnetLog.txt': No such file or directory in /hsphere/local/home/twatters/gwatters.com/ta2/upload.php on line 92

Line 92 is:

Code: Select all

<?php
		copy($file, "$absolute_path/$file_name");
?>
It looks like your source file is $file_name.
Did you try

Code: Select all

copy($file_name, "$absolute_path/$file_name");
Steve
SL-Cowsrule
Forum Newbie
Posts: 13
Joined: Sat Oct 12, 2002 5:08 pm

Post by SL-Cowsrule »

thanks, i got it working :)

CoW
Post Reply