Help debug my upload.php

Hi, Yes this is a demo from http://www.tizag.com/phpT/fileupload.php

however it does not work, it comes up as echo not writeable even tho my file is on 777 persmissions.

anyideas would be appricated.

Cheers.

it comes up with not writeable :S
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>


///////////////////////Upload code/////////////

<?
// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = "./uploads/".basename($_FILES['uploadedfile']['name']);
 
if (is_writable("./uploads/")) {
    echo "Is Writable";
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
} else {
    echo "Is not Writable";
}
 

?>

Open in new window

LVL 6
NeoAshuraAsked:
Who is Participating?
 
Beverley PortlockConnect With a Mentor Commented:
"Not writeable" is a permissions error, not a PHP script error.

The folder you are trying to write to will not let the webdaemon have access to create a new file. Either change the group ownership of the folder or (simplest of all) set the permissions for the folder to 777 to allow universal access.
0
 
NeoAshuraAuthor Commented:
i set the access to 777 as i started in my opening comment. still no luck. I have got a file named uploads in my web root and also in the folder where my uploadform is stored. still no joy.
0
 
Beverley PortlockCommented:
Sorry - I missed the 777 comment in your original post.

For folder the execute bit (the x in rwx) needs to be set so if the parent folder of the folder you are trying to write to has no "x" bit set then the folder in question will not be accessible.

Next is the folder where you think it is? Are you sure that the ./uploads folder is where you expect it to be? Try altering the script to look like this (see http://www.php.net/realpath )

echo "Attempting write to " . realpath( "./uploads" );
 
if (is_writable("./uploads/")) {
    echo "Is Writable";
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
} else {
    echo "Is not Writable";
}
 

Next, check spelling make sure your folder is "uploads" and not "upload" or "Upload" or "Uploads", etc.
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.

 
PrograministratorConnect With a Mentor Commented:
Hello,

is_writable returns that "upload" folder not writable,

change the permission of this folder!

if its permissions already 777,

so check the php safe mode of change your condition to another function than is_writable
0
 
PrograministratorCommented:
Sorry, for typo

"so check the php safe mode, or change your condition to another function than is_writable".

Pay attention, you should to change the permissions of the folder that you're uploading to it,

not permissions of the php file or the file that you're uploading, and not the permissions of the folder that you're uploading from.

"uploads" folder's permissions is that should to be changed.

Good luck.
0
 
NeoAshuraAuthor Commented:
ok now it coming up as IT IS WRITEABLE but its not uploading :S im so confused. its 777 it says now its writeable but still doesnt upload my file (just a standard 2kb text file)
0
 
dsmileConnect With a Mentor Commented:
Two things:
1. is "./uploads" path correct (relatively to your script)?
2. try to call clearstatcache() before checking writing permission
0
 
dsmileCommented:
Try to use this

$target_path = "./uploads/".$_FILES['uploadedfile']['name'];


instead of

$target_path = "./uploads/".basename($_FILES['uploadedfile']['name']);
0
 
NeoAshuraAuthor Commented:
okk what ive got now is as follows..

<?
error_reporting(E_ALL);
// Where the file is going to be placed
$target_path = "uploads";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = "./uploads".basename($_FILES['uploadedfile']['name']);
 
 echo "Attempting write to " . realpath( "./uploads" );

 
if (is_writable("./uploads")) {
    echo "Is Writable";
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
} else {
    echo "Is not Writable";
}
 

?>


and the output is...of the echo is as follows :

Attempting write to (correct path)/uploadsIs Writable
0
 
PrograministratorCommented:
What is the size of the file you're attempting to upload?

check this values in your php.ini :

post_max_size
upload_max_filesize
memory_limit


0
 
NeoAshuraAuthor Commented:
its 2kb so shouldnt be a prblem.
0
 
dsmileCommented:
Your latest code is missing a slash in $target_path

$target_path = "./uploads".basename($_FILES['uploadedfile']['name']);

Should be

$target_path = "./uploads/".basename($_FILES['uploadedfile']['name']);

And I don't think basename is necessary, so this is enough

$target_path = "./uploads/".$_FILES['uploadedfile']['name'];
0
 
NeoAshuraAuthor Commented:
ok problem solved, i just did another tutorial from a diffrent site and it worked, i appricate peoples time so points will be awarded fairly. thanks.
0
 
Beverley PortlockCommented:
Place alter this

error_reporting(E_ALL);

to this

ini_set("display_errors", 1);   error_reporting(E_ALL);

in display_errors is OFF - this would prevent error_reporting from showing anything. Also change the following code

if (is_writable("./uploads")) {
    echo "Is Writable";
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);
} else {
    echo "Is not Writable";
}

to report the statement it is about to run (like so)

if (is_writable("./uploads")) {
    echo "Is Writable";
    echo "move_uploaded_file({$_FILES['uploadedfile']['tmp_name']}, $target_path)");
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path);

exit;  //   <--- get rid of this after testing

} else {
    echo "Is not Writable";
}


You will notice that it contains an exit statement to stop execution immediately after the move. This is to ensure that nothing else interferes until we are certain that we know the upload works.
0
 
Beverley PortlockCommented:
LOL! I see I need to type faster.

;-)

Glad you're sorted
0
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.

All Courses

From novice to tech pro — start learning today.