Current location: Hot Scripts Forums » Programming Languages » PHP » Upload Issue


Upload Issue

Reply
  #1 (permalink)  
Old 06-20-07, 12:57 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Spin Upload Issue



PHP Code:

    // Valid file Mime types / extension

    
$allowed_types = array(
        
"image/jpeg" => "jpg""image/gif" => "gif"
        
// Add more types here if you like
    
);
   
    
    
// Set the maximum file size => 204800 = 200kb
    
$maxfilesize 5048000;
    
    
// Is it under the allowed Max file size?
    
if($_FILES['userfile']['size'] > $maxfilesize) {
        die(
"<center><font color=\"#000000\" size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">File is too large!</font></center>");
    }
    
    
// Where are the files going?
    
$uploaddir $_SERVER['DOCUMENT_ROOT'] . "/dev/photos/";
    
    
// What is the files temporary name?
    
$file $_FILES['userfile']['tmp_name'];
    
    
// What is the files actual name?
    
$filename $_FILES['userfile']['name'];
        
    
// Check to see if the file allready exists?
    
if(file_exists($uploaddir $filename)) {
        die(
"<center><font color=\"#000000\" size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">A file with that name already exists on this server.</font></center>");
    } else {
        
// If the file does not already exist, copy it.
        
copy($file$uploaddir.$filename) or die("<center><font color=\"#000000\" size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Could not copy file.</font></center>");
    } 
Im not sure whats wrong in this script.

When the script is Executed I either get

"A file with that name already exists on this server."

or

"Could Not Copy"

everything is turned on from the server side as well
Reply With Quote
  #2 (permalink)  
Old 06-20-07, 01:27 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
check the 'error' key in the $_FILES['userfile'] array. It will show you a number which refers to an error that occured during the file upload. Explanations of the errors can be found here:
http://be.php.net/manual/en/features...oad.errors.php
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 06-20-07, 01:45 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Hey Ed Thanks -- I echoed it out and i didnt recieve anything back from it

PHP Code:

echo $_FILES['error']; 

Reply With Quote
  #4 (permalink)  
Old 06-20-07, 01:55 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
you have to use this:
PHP Code:

echo $_FILES['userfile']['error']; 

$_FILES is a multidimensional array, and just like 'name', 'error' is a key of the nested array
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 06-20-07, 02:07 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
i tried the code echo statement above and nothing came up again.
Reply With Quote
  #6 (permalink)  
Old 06-20-07, 02:30 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
hmmm
add the following two lines on top of your code. I think the errors aren't displayed:
PHP Code:

error_reporting(E_ALL);
ini_set('display_errors''1'); 
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 06-20-07, 02:33 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
ok now im getting a error - undefined index.

Check it for your self........
http://glp-msl.com/dev/cp/process/im...ad_process.php
Reply With Quote
  #8 (permalink)  
Old 06-20-07, 02:36 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
ah, the reason why your script isn't working, is because you're referring to the wrong html file element . Can you post your entire code please?
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #9 (permalink)  
Old 06-20-07, 03:39 PM
tommyc325's Avatar
tommyc325 tommyc325 is offline
Wannabe Coder
 
Join Date: Sep 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
The upload script is part of a process page.


this is the form from the previous page:

HTML Code:
<form action="process/imageupload_process.php" method="POST" enctype="multipart/form-data" name="form3">
          <table width="371" height="165" border="0" cellpadding="2" cellspacing="2">
            <tr>
              <td colspan="2" class="content">Caption:</td>
            </tr>
            <tr>
              <td height="84" colspan="2"><label></label>
                <label>
                <textarea name="caption2" cols="40" rows="5" class="content" id="caption2"></textarea>
                </label></td>
            </tr>
            <tr>
              <td width="37" class="content">Group:</td>
              <td width="320"><label>
                <select name="group" class="content" id="group">
                  <option value="design1">Group 1</option>
                  <option value="design2">Group 2</option>
                  <option value="design3">Group 3</option>
                </select>
              </label></td>
            </tr>
            <tr>
              <td class="content">Upload:</td>
              <td><label>
                <input name="upload" type="file" class="content" id="upload">
              </label></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><label>
                <input type="submit" name="button2" id="button2" value="Submit">
              </label></td>
            </tr>
          </table>
            <input type="hidden" name="MM_insert" value="form3">
        </form>

Last edited by UnrealEd; 06-20-07 at 03:41 PM.
Reply With Quote
  #10 (permalink)  
Old 06-20-07, 03:42 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
HTML Code:
<input name="upload" type="file" class="content" id="upload">
the name of the element is upload, not userfile

If you just change the name to userfile, it should work
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

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
Perl upload progress bar with these spec: scott2500uk Script Requests 4 03-16-07 04:04 PM
Firefox Image Upload Issue klassix PHP 2 02-25-07 10:46 AM
i have a file upload issue.... stormshadow PHP 5 12-03-05 09:57 PM
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP Script Request DazzlyWorks Script Requests 0 01-16-05 01:23 PM


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