Help With This Uploading Script?

Status
Not open for further replies.

MrLogic

Member
Nov 28, 2012
118
4
Im trying to make a uploading script and it uploads,just doesnt show the uploaded pic.Heres the code:
HTML:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100" />
What Do You Want To Upload? <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
Any help appreciated!
 

MrLogic

Member
Nov 28, 2012
118
4
Post uploader.php

PHP:
<?php
$target_path = "./uploads/";
 
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
You can do it in cPanel. 777 means all permissions are set, you can read, write and execute scripts which is what you need for an uploading script, you want all 3.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,396
960
Im trying to make a uploading script and it uploads,just doesnt show the uploaded pic.!
Now that I reread what you were asking, you can see why it doesn't show the uploaded pic by this part:

PHP:
echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";

All that's doing is showing the filename that was uploaded. If you wanted to show the image, you would need to use something like:

<img src=" echo 'basename($_FILES['uploadedfile']['name']); ?>" />
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
It's actually more secure to use 755 instead of 777 (depends on Apache setup really).

I'll take a look at this script later.
Yes of course it is, but he wants to be able to upload files to the directory, so it has to be set to 777 so he can 'write' to the directory.. as in put files there.
 

Ecko

23:37 [autobots] -!- eckostylez [[email protected]]
Nov 25, 2012
1,396
960
Yes of course it is, but he wants to be able to upload files to the directory, so it has to be set to 777 so he can 'write' to the directory.. as in put files there.
That's why I said it depends on the Apache setup really :p

If you are running mod_suphp (have PHP running as CGI), then you can only use 755 because you are writing to the directory as the owner (instead of as the Apache user). suPHP is actually more secure and flexible and will give Internal Server Errors if you chmod a directory to 777.
 
Status
Not open for further replies.

Users who are viewing this thread

Top