PHP Upload script

Electronics Computer Programming Q&A
Post Reply
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

PHP Upload script

Post by Mike » Mon Aug 07, 2006 6:37 pm

I'm trying to allow uploads to my server through PHP. I know it's possible and I've found many scripts on the internet, however they are far too complicated for me especially since I do not need all the features they include like file type checking, size limits, etc. You can only upload to my server through a hidden page after entering a password as well, so I know and trust the people who will use it. Is there a simple way for me to allow users to upload files to my server? Not that it really matters but they will be jpeg image files.

Any ideas how to do this?

Thanks

User avatar
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi » Sat Aug 12, 2006 4:46 am

on one of my sites has an up load.... I do something like this

http://www.tizag.com/phpT/fileupload.php


I would be careful.. if the public gets a hold of this page.. bad news! There is ways to block google from pages.. I would do so.

I would post how my page looks but again... with all the spam we get on this forum, I wont take my chances.

Hope that helps.. if you want the code that I have let me know.

Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Post by Mike » Sat Aug 12, 2006 5:07 am

Google nor any other search engine should be able to get in. They do not have the username and password, so the worst they could do is figure out that thee is a folder named /Admin, but not get in. Plus, there is no link to the admin folder on any page, so I don't even think any search engine crawler could get ahold of it. And if they did, they don't know the username and password.


So, how this works is it POST's the data to the uploader.php, which then contains both parts of the code? So, basically uploader.php would contain the following code and that is it? I've also modified the directory it places the files in, I assume that is OK to do?

Code: Select all

// Where the file is going to be placed 
$target_path = "/images/";

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

$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!";
}

If you could send me your code you used as well, I would really appreciate it!

Thanks,
Mike

User avatar
Sambuchi
Posts: 366
Joined: Tue Jan 18, 2005 1:01 am
Location: Orlando FL
Contact:

Post by Sambuchi » Mon Aug 14, 2006 6:59 am

Hey Mike

I've been busy..sry for leaving you hanging on this one.


Are you able to upload using that example?

I will leave this link up for a little bit..

www.XXXXXXXXXXXX/upload/upload.html

I will be doing the example I posted.

So this is how I have it setup..

I have a folder.. in it i have the following..
-----------------------------------
upload.html
uploader.php
FOLDER CALLED uploads
-----------------------------------

upload.html

Code: Select all

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />

<br>
<br>
<br>
<p><a href="http://www.sambuchi.net/PHP/upload/tree.php">Show the contents of uploads</a></p>

</form>


uploader.php

Code: Select all

<?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!";
}


?>
That is all you need for it to work.. you can try to upload something to my server if you like to see it work... be sure to keep the file under 50k.. if you try to go over 50k you will get a message that says.. file didnt upload.

I uploaded a one picture for an example.

Hope that helps Mike.. Let me know.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests