SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old September 28th, 2004, 01:39 PM
OmegaDeuce OmegaDeuce is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 OmegaDeuce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy File uploads in PHP5

Ive searched the forums but cant seem to find any help. I am trying to program a simple script that allows users to uploaded either a word document or a powerpoint presentation. I haven't the slightest idea how to start this code. Any help would be greatly appreciated.

Reply With Quote
  #2  
Old September 28th, 2004, 05:33 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
There are loads of tutorials on this all over the internet. Do a google search and see what you turn up.

-KM-

Reply With Quote
  #3  
Old September 28th, 2004, 09:56 PM
subra subra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 subra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

i'm also looking for one. the one i found out, does not work
as it shld be. can someone help me !
i need to upload file from windows (word/excel/etc) to linux.
But the problem is, after uploading, the file size getting larger and the file
is totally corrupted!

Reply With Quote
  #4  
Old September 30th, 2004, 12:18 AM
xlordt xlordt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: 127.0.0.1
Posts: 20 xlordt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 39 sec
Reputation Power: 0
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt
here is how i do it.
PHP Code:
<?php

   $upload_dir 
'temp/';
   
   if( 
$_POST['submit'] )
   {
       
$name $_FILES['users_f']['name'];
       
$tmpn $_FILES['users_f']['tmp_name'];
       
       if( empty( 
$name ))
       {
           print 
'You didnt upload a file, Please try again';
           print 
'<meta http-equiv="refresh" content="2; url=' $PHP_SELF '">';   
           exit;
       }
       
       if( 
preg_match'/\.doc$/'$name ))
       {
           
$name str_replacestrstr$name'.' ), '.txt'$name );
       }       
       
       
$rname str_replacestrstr$upload_dir $name'.' ), '.doc'$upload_dir $name );
           
       if( !
move_uploaded_file$tmpn$upload_dir $name ))
       {
           print 
"The upload has failed, please try again later ( $upload_dir $rname )";
           print 
'<meta http-equiv="refresh" content="2; url=' $PHP_SELF '">';
           exit;
       }
       
       
chmod$upload_dir.$name0777 );
       
rename$upload_dir.$name$rname );
       
       print 
'File ' $_FILES['users_f']['name'] . ' successfuly uploaded :)';
       print 
'<meta http-equiv="refresh" content="2; url=' $PHP_SELF '">';
       exit;
       
   }       
   
?>


<form enctype="multipart/form-data" action="<?php echo $PHP_SELF?>" method="post">
  <input type="hidden" name="MAX_FILE_SIZE" value="50000" />
    Select File: <input name="users_f" type="file" />
  <input type="submit" name="submit" value="Upload File" />
</form>

works like a charm, never failed for me, also just incase.. you can always use an extra variable to hold the files extension if you want to use different file uploads

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > File uploads in PHP5


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway