Dynadot — .com Registration $8.99

PHP Upload

Spaceship Spaceship
Watch

Greenie

New Member
Impact
0
Can somebody write a quick php script for me that uploads files, much like imageshack does (renames the files to avoid collisions) and stores them on the server. Thanks alot..

P.S Nothing complex is required :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Form.php:

<FORM NAME="uploadfile" METHOD="post" ACTION="upload.php" enctype="multipart/form-data">
File: <INPUT TYPE="file" NAME="file"> <INPUT TYPE="submit" NAME="submit" VALUE="Upload">
</FORM>

Upload.php:

<?
if (isset($submit)) {
foreach ($_FILES as $file) {
if (move_uploaded_file($file['tmp_name'], "/path/to/upload/dir/".$file['name'])) {
echo "File Uploaded!";
}
else
{
echo "File Upload Failed";
}
}
}
?>

Note: I just threw this together in about 30 seconds. Just an example of what you're looking at roughly - I don't suggest copy and pasting this and using it live. Obviously you'll want some more security checking and stuff.
 
0
•••
Greenie said:
(renames the files to avoid collisions)

Just a note, php already does this. Files are renamed in the temp folder (although the old file name is available in the $_FILES array.
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back