Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] PHP file sending


[SOLVED] PHP file sending

Reply
  #1 (permalink)  
Old 04-15-08, 06:28 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP file sending

I have a HTML form with:

Code:
<input type="file" name="pimage" size="30" />
I want to select a picture from desktop, and I want to put this picture in a specific folder after form submit.

Which PHP function I need to use?
Thanks!
Reply With Quote
  #2 (permalink)  
Old 04-15-08, 06:30 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
move_uploaded_file().

Read this page for more info about file uploading:
www.php.net/features.file-upload
Reply With Quote
  #3 (permalink)  
Old 04-15-08, 07:04 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I need to use this function: move_uploaded_file() after or before file upload?
Reply With Quote
  #4 (permalink)  
Old 04-15-08, 07:06 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You can't use it before.

When you submit the form, the file will be sent (uploaded) to your server. No code will be executed until it's fully uploaded.
Reply With Quote
  #5 (permalink)  
Old 04-15-08, 07:24 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I use this code:

PHP Code:

$uploaddir 'd:\wamp\www\mycart\images\produse';
$uploadfile $uploaddir basename($_FILES['userfile']['name']);
        
if (
move_uploaded_file($_FILES['pozaprod']['tmp_name'], $uploadfile)) {
     
// Upload OK
} else {
       
// Upload failed

I get this error every time:

Warning: move_uploaded_file(d:\wamp\www\mycart\images\produ se) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\wamp\www\mycart\admincp\addprod.php on line 54

BTW is possible to remove the "D:\wamp\www\mycart" from upload dir ?
Sorry because I ask much but I need to finish a school project fast as possible.

Last edited by Nico; 04-15-08 at 07:58 AM. Reason: Please use [php] wrappers for PHP code.
Reply With Quote
  #6 (permalink)  
Old 04-15-08, 07:39 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
OK the problem is solved. Is possible to get the uploaded file name for example: landscape.jpg after file is uploaded and moved... I need to write the file name in database. Thanks!
Reply With Quote
  #7 (permalink)  
Old 04-15-08, 07:58 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You have the solution in the code you posted above.
Reply With Quote
  #8 (permalink)  
Old 04-15-08, 08:20 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
thanks! I safe to insert this $_FILES['userfile']['name'] in database?
Reply With Quote
  #9 (permalink)  
Old 04-15-08, 08:24 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Since it comes from the user and you don't know what it can contain, you should apply mysql_real_escape_string().
Reply With Quote
  #10 (permalink)  
Old 04-15-08, 10:17 AM
blinn_shade's Avatar
blinn_shade blinn_shade is offline
Aspiring Coder
 
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
You might also want to add some security to this. Such as which file types are allow to be uploaded & the size of the file allowed to be uploaded.
__________________
Can you think outside the box but remain inside the box?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP write to text file veeco Script Requests 2 02-10-10 02:48 PM
PHP File Upload/User Manager Script Needed Computra Script Requests 2 11-09-05 02:39 PM
PHP based File Tracker project valtea Script Requests 0 09-08-05 02:04 PM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
PHP File counter brambulkens PHP 7 05-14-05 06:20 AM


All times are GMT -5. The time now is 07:42 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.