Current location: Hot Scripts Forums » Programming Languages » PHP » upload script


upload script

Reply
  #1 (permalink)  
Old 09-24-03, 07:56 PM
cabj1981 cabj1981 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
upload script

i'm having a problem with this script, it runs but when i hit upload, it dosen't save to the folder. i check the path of the folder and it is okey.

dose some one know how to fix it.

oh yeah how can i confg the directory to 777?
Reply With Quote
  #2 (permalink)  
Old 09-24-03, 08:03 PM
Patriarch Patriarch is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Cab:

You're probably right to assume it is a permissions error, it does sound like this is the case.

Your FTP client should have a CHMOD function built-in somewhere, I know with mine (WS_FTP LE) all you need to do is right-click and select CHMOD.

Hopefully allowing write permissions on the folder should solve the error.
Reply With Quote
  #3 (permalink)  
Old 09-24-03, 08:15 PM
cabj1981 cabj1981 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
the thing is that i'm runing the web server from my computer. the name of the web server is Abyss Web Server i don't think they have ftp
Reply With Quote
  #4 (permalink)  
Old 10-24-03, 05:20 PM
alfreds's Avatar
alfreds alfreds is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

To set the chmod 777 for your upload dir for windows environment (I suppose you have that) just right-click the upload folder -> select 'Properties', then select 'Sharing' -> 'Share this folder' -> and finally 'Permissions...' -> click all of the checkboxes.

If you are using linux, than i have no idea. I am sure others will tell you! Ask some of your computer guru friends!

Here is a code for file upload that should work. In case not, consult the php online manual, where there are a lot of user comments on the best methods of file upload.

So, here is the working code:

PHP Code:

<?php



// "/images/" is the way to file upload directory 
// from your webservers document root.
// To see the output dir for this script to save
// your upload file, run this script and look at 'Upload dir:'
// displayed before file upload.

$upload_dir $_SERVER['DOCUMENT_ROOT'] . "/images/";

?>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">

Upload dir: <b><?php print "$upload_dir"?></b><br/>

  <input type="hidden" name="MAX_FILE_SIZE" value="300000000">
  <input type="file" name="upfile">
  <input type="submit" name="resize" value="Upload">
 
 </form>
 </td>
</tr>
</table>
<?
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $upload_dir $_FILES['upfile']['name']))  {
print 
"Upload success!";
}

?>
The idea is this:
- If no file upload has happened, print form.
- When upload is done, file is uploaded (and checked for the upload at the same time) and success message is displayed.


See, if helps!
Alfreds

Last edited by alfreds; 10-24-03 at 05:25 PM.
Reply With Quote
  #5 (permalink)  
Old 10-24-03, 09:08 PM
minghoo minghoo is offline
New Member
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi, alfreds

very nice scripts.

but i have one questions: how can i add more upload fields in this scripts

<input type="file" name="upfile">

if i want upload Multiple files in same times, how can i modify this scripts?


thanks
sean
Reply With Quote
  #6 (permalink)  
Old 10-24-03, 09:30 PM
cabj1981 cabj1981 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
holy****

i tried to get so many upload scripts to work for so long. I think it was like 3 weeks and and like ten upload scripts but nothing worked.I just tested your upload script and it works fine how did you do it or what was i doing wrong. You are the men!!!


Thanks...
Reply With Quote
  #7 (permalink)  
Old 10-24-03, 09:41 PM
cabj1981 cabj1981 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
me again

how can i hide where i'm uploading the images to and the notice.
Reply With Quote
  #8 (permalink)  
Old 10-25-03, 03:11 AM
alfreds's Avatar
alfreds alfreds is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
About multiple uploads. This is a bit complex, but i made it working when i was doing file upload thing. I will write the code here down soon!
Reply With Quote
  #9 (permalink)  
Old 10-25-03, 04:13 AM
alfreds's Avatar
alfreds alfreds is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Here is the code for multiple uploads. put it into a single file and execute it!

PHP Code:

<?php

// Set the upload place, after your document root directory
$upload_dir $_SERVER['DOCUMENT_ROOT'] . "/upload/";


if (isset(
$_POST[submit]))  {
    
    
// Write as many file upload
    // inputs as user wanted
     
$file_amount $_POST['file_amount'];
    
$counter 1;
    
    while (
$counter <= $file_amount) { 
           
$foto_input .= "$counter. file: <input name='filename[$counter]' type='file'><br />\n";
           
$counter++; 
    }
    
    
// Generate an html output
    // where to display the file
    // upload fields
    
    
print "<form enctype='multipart/form-data' action='$PHP_SELF' method='post' name='upload_form'> 
                 <table width='100%' border='0' align='center'> 
                   <tr><td>
                    <li>Upload path: 
$upload_dir</li>\n
                    <li>Amount of files to upload: <b>
$file_amount</b></li>\n
                   </td></tr>\n
                <tr><td>
$foto_input</td></tr>\n
                <tr><td><input type='submit' name='upload' value='Upload Files'></td></tr>\n
                </table>\n
            </form>\n"
;
} else {
    
// Generate the form
    // for user to select how many uploads he
    // wants to do.
    
     
print     "<form name='gallery_setup' method='post' action='$PHP_SELF'>" .
              
"Number of photos to upload:" .
            
"        <input name='file_amount' type='text' id='file_amount' size='10'>" .
            
"        <input type='hidden' name='MAX_FILE_SIZE' value='300000000'>" .
            
"        <input name='submit' type='submit' id='submit' value='submit'> " .
             
"</form>";
}



if (isset(
$_POST[upload]))  {
        
    
// Get the upload file array
    // and upload them to a destination
    // by looping through that array
    
    // Get the variables from previous form
    
$up_files $_FILES['filename'];
    
$counter 0;
    
    
// Start the file upload to server
    
while($counter <= count($up_files))  {
        
        if(
$up_files['size'][$counter] > 0) { 
            
$filetype $up_files['type'][$counter];
            
$filename $up_files['name'][$counter];
            
$tempname $up_files['tmp_name'][$counter];
            
            
$upload_file $upload_dir $filename;
            
// Upload the files 
            
move_uploaded_file($tempname$upload_file);
            
            
// Print the uploaded file
            
print "File <b>$filename</b> uploaded... new location: <b>$upload_file</b><br />";
         }
         
$counter++;
    }
// End if upload
}

?>
By the original, I used it for image file upload and thumbnail generation, so do not be confused if you see some variables named after 'foto' and etc.


To cabj1981:
To hide the location and success message simply delete the following line in previous code i posted:

Upload dir: <b><?php print "$upload_dir"; ?></b><br/>

print "Upload success!";


Hope this makes a lot of things clear!
Sincerely,
Kaspars Dambis
Reply With Quote
  #10 (permalink)  
Old 10-25-03, 07:45 AM
cabj1981 cabj1981 is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
hey

Sorry for so many questions. How do i change the file type because i don't want the user to upload .exe types of files. i want to upload *.mp3,*.dwg,*.jpeg,*.gif

Thanks alot for the script...
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
Looking for a good review management script griz_fan Script Requests 10 07-29-07 05:08 AM
Image Upload Script GrimShadow PHP 1 09-26-03 05:18 PM
Run a Website? Create a Script? Upload it Free epic1231 General Advertisements 0 09-22-03 11:58 AM
upload script abbus00 New Members & Introductions 0 07-08-03 05:23 AM
Looking for a script to upload images in a database. boskyvora PHP 2 06-16-03 04:18 AM


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