Current location: Hot Scripts Forums » Programming Languages » PHP » Uploading file from the web server

Uploading file from the web server

Reply
  #1  
Old 07-11-09, 03:29 AM
prince13 prince13 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Uploading file from the web server

Hi,

I am new to php but i like to mess around with code.

What i am trying to do is...

scan a directory with image and once i got them send them to the upload_media function of my CMS. But the problem is that my upload_media function doesnt accept the array or anything. it performs the upload from the submited form on the frontend( $_FILES[ ][ ] ). Since i am working on the backend and trying to send images from the webserver i am having hard time figuring out how to send the post upload request so that my upload_media function can perform the upload.

Can anyone of the php guru's here help me out. Thanks
Reply With Quote
  #2  
Old 07-12-09, 06:22 PM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,560
Thanks: 2
Thanked 25 Times in 25 Posts
The PHP gurus need to see some code and a bit more information.

Specifically - the CMS (including the version), you're using, and any custom code you've added.
Reply With Quote
  #3  
Old 07-12-09, 06:41 PM
prince13 prince13 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
its social engine 3.15 and i am working with the groups plugin for social engine. i am trying to populate groups. which works fine...but i dont wanna add images to it 1 by 1....they way groups are created is based on the directory structure and then in each directory there are images. i wanna send those images to group_media_upload function in class_groups.php But that functions uses $_FILES array and doesnt accept any file. How can i pass data to $_Files? is it possible to pass data to global array $_Files ??
Reply With Quote
  #4  
Old 07-12-09, 08:28 PM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,560
Thanks: 2
Thanked 25 Times in 25 Posts
You should go to the support site for social engine.
Reply With Quote
  #5  
Old 07-12-09, 10:56 PM
prince13 prince13 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
they dont wanna provide support for this custom modification.
thanks
Reply With Quote
  #6  
Old 07-13-09, 06:10 AM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,560
Thanks: 2
Thanked 25 Times in 25 Posts
Usually, there are forums, like this one, where other people will help you, possibly even the person that wrote the custom modification.

There are so many products available that it really is best to get product-specific help from the source.

You're welcome here - but you need to post enough code for people to help you.

I've never heard of social engine. I can guess it is social networking script.

If you want help, post the form code that you are using to upload the form, and the PHP that is receiving it.

And, please, write clearly and carefully. I don't 'wanna' help someone that is not serious enough to write well.
Reply With Quote
  #7  
Old 07-13-09, 11:58 AM
prince13 prince13 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
This is the code that i am using to loop through directory and get the images from it.
PHP Code:
                                       if ($location) {
                                        
                                            
$path $location;
                                            
$dir_handle = @opendir($path) or die("Unable to open folder");
                    
                                            
$filecount 0;
                                            
$file_result = Array();
                                            
                                            while (
false !== ($file readdir($dir_handle))) {
                                                if (
ereg("(.*)\.(jpg|bmp|jpeg|png|gif)"$file))
                                                {

                                                    
$fileid "file".$filecount;
                                                    
$_FILES[$fileid]['name'] = $file;
                                                    
//array_push($_FILES,$file);
                                                    
$filecount++;
                    
                                                }
                    
                    
                                            }
                                            
closedir($dir_handle); 

This is the code what i am using to send each file to the function.
PHP Code:
 for($f=1;$f<6;$f++)
  {
    
$fileid "file".$f;
    if(
$_FILES[$fileid]['name'] != "")
    {
      
$file_result[$fileid] = $group->group_media_upload($fileid$groupalbum_info['groupalbum_id'], $space_left);
}

PHP Code:
function group_media_upload($file_name$groupalbum_id, &$space_left)
  {
      global 
$database$url$user;
    
      
// SET KEY VARIABLES
      
$file_maxsize $this->groupowner_level_info['level_group_album_maxsize'];
      
$file_exts explode(","str_replace(" """strtolower($this->groupowner_level_info['level_group_album_exts'])));
      
$file_types explode(","str_replace(" """strtolower($this->groupowner_level_info['level_group_album_mimes'])));
      
$file_maxwidth $this->groupowner_level_info['level_group_album_width'];
      
$file_maxheight $this->groupowner_level_info['level_group_album_height'];
    
      
$new_media = new se_upload();
      
$new_media->new_upload($file_name$file_maxsize$file_exts$file_types$file_maxwidth$file_maxheight);

..... .... ..... ..... 

PHP Code:
    function new_upload($file$file_maxsize$file_exts$file_types$file_maxwidth ""$file_maxheight "")
  {
                
      
// GET FILE VARS
      
$this->file_name $_FILES[$file]['name'];
      
$this->file_type strtolower($_FILES[$file]['type']);
      
$this->file_size $_FILES[$file]['size'];
      
$this->file_tempname $_FILES[$file]['tmp_name'];
      
$this->file_error $_FILES[$file]['error'];
      
$this->file_ext strtolower(str_replace("."""strrchr($this->file_name"."))); 

.... ... .... .. 

The upload page for the users who are asked to upload files uses form post. just like any other upload form. But since i am trying to do that from the php server side i am looking for a way to correctly populate the $_FILES array with the data that i wanna send to the upload function of the CMS because that function uses $_FILES array inorder to process the uploaded files.


Can you help with this?

thanks
Reply With Quote
  #8  
Old 07-13-09, 11:46 PM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,560
Thanks: 2
Thanked 25 Times in 25 Posts
If the $_FILES values you set are being passed to the upload script - you should continue with your current approach. Be sure to populate all the fields used.

I think you're going to need a custom function or an import process - the $_FILES array is populated by the server. An option you may want to consider is cURL.

PHP: curl_setopt - Manual
Reply With Quote
  #9  
Old 07-14-09, 12:02 AM
prince13 prince13 is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply

I understand that i must populate all the fields. I dont understand what will be pushed in $_FILES[$file]['tmp_name']; ??? i cant keep that empty rite?
Reply With Quote
  #10  
Old 07-14-09, 06:50 AM
wirehopper's Avatar
wirehopper wirehopper is offline
Community Liaison
 
Join Date: Feb 2006
Posts: 1,560
Thanks: 2
Thanked 25 Times in 25 Posts
Try putting the name of the file as it exists on the server in 'tmp_name'.

This approach (using $_FILES) may work, but I think it's a gamble. If you only need the application to run on the server you're working on, you'll probably be fine, however, if you are planning to distribute the code or use a different server, you may want to find a different method.
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Form that writes to a text file on the web server...? ViciousTruth Script Requests 10 03-05-09 05:44 PM
File uploading. Quick question! staticfire PHP 4 08-24-07 06:47 PM
PHP - Transfer file from one server to another. NabZ PHP 5 05-30-07 11:45 AM
Your File is uploading Popup scott2500uk JavaScript 6 03-20-07 06:36 PM


All times are GMT -5. The time now is 03:08 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)