?
Solved

Help debug my upload.php

Posted on 2010-11-16
15
Medium Priority
?
290 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 668 total points
ID: 34146463
"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
ID: 34146491
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
ID: 34146613
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Assisted Solution

by:Prograministrator
Prograministrator earned 668 total points
ID: 34146633
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
ID: 34146745
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
ID: 34146755
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 664 total points
ID: 34146768
Two things:
1. is "./uploads" path correct (relatively to your script)?
2. try to call clearstatcache() before checking writing permission
0
 
LVL 13

Expert Comment

by:dsmile
ID: 34146801
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
ID: 34146826
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
ID: 34146908
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
ID: 34146955
its 2kb so shouldnt be a prblem.
0
 
LVL 13

Expert Comment

by:dsmile
ID: 34147011
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
ID: 34147013
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
ID: 34147066
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
ID: 34147077
LOL! I see I need to type faster.

;-)

Glad you're sorted
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 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