Solved

Help debug my upload.php

Posted on 2010-11-16
15
235 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:NeoAshura
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 167 total points
Comment Utility
"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
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
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
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
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
 
LVL 3

Assisted Solution

by:Prograministrator
Prograministrator earned 167 total points
Comment Utility
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
 
LVL 3

Expert Comment

by:Prograministrator
Comment Utility
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
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
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
 
LVL 13

Assisted Solution

by:dsmile
dsmile earned 166 total points
Comment Utility
Two things:
1. is "./uploads" path correct (relatively to your script)?
2. try to call clearstatcache() before checking writing permission
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:dsmile
Comment Utility
Try to use this

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


instead of

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

Author Comment

by:NeoAshura
Comment Utility
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
 
LVL 3

Expert Comment

by:Prograministrator
Comment Utility
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
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
its 2kb so shouldnt be a prblem.
0
 
LVL 13

Expert Comment

by:dsmile
Comment Utility
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
 
LVL 6

Author Comment

by:NeoAshura
Comment Utility
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
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
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
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
LOL! I see I need to type faster.

;-)

Glad you're sorted
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now