Need Help: File Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Good news, I got it to work. Just a tip: when you're having trouble sometimes its just that the variable isn't what it's supposed to be. In order to debug I like to echo() all the variables right before the function just to make sure that they are all what I want them to be. In this case I just called the following line before the first if statement.

Code: Select all

<?php
echo "Filename=$filename<br>Extension=$extension";
?>
I noticed that the $extension displayed was "zip" and not ".zip". I forgot that explode() takes out the period. I then changed the upload extension variables to

Code: Select all

<?php
$uploadext1="zip";
$uploadext2="ZIP";
?>
The script then worked perfectly. Let this be a lesson to all of us :wink: .
stonerifik
Forum Newbie
Posts: 23
Joined: Thu May 22, 2003 7:45 pm
Location: united states
Contact:

Post by stonerifik »

:D thank you so much! it is working perfectly now... ill take ur advice on the tip thank you!
stonerifik
Forum Newbie
Posts: 23
Joined: Thu May 22, 2003 7:45 pm
Location: united states
Contact:

Post by stonerifik »

sorry for this... but yeah the code i did still works.. but instead of saying successful, it says error...

Code: Select all

<? 
$uploaddir = $_SERVER['DOCUMENT_ROOT']."/downloads/".$_POST['directory']."/"; 
$uploadext1="zip"; 
$uploadext2="ZIP"; 
list($filename,$extension) = explode(".",$_FILES[file1][name]); 
if($extension==$uploadext1 || $extension==$uploadext2) 
{ 
if ($_FILES[file1] != "") { 
  copy($_FILES[file1][tmp_name], $uploaddir .$_FILES[file1][name]) or die("Couldnt Upload File"); 
  } 
else { 
  die("No file selected for upload"); 
  }  
} 
else { 
  die( "File is not the correct format, only .zip is allowed."); 
} 
?> 




<HTML> 
Upload Successful 
</HTML>
i dont know what is wrong.. plz help... sorry again
stonerifik
Forum Newbie
Posts: 23
Joined: Thu May 22, 2003 7:45 pm
Location: united states
Contact:

Post by stonerifik »

well after messing with it a couple hours.. i learned that, that file uploaded needs to have mass, or rather size to it... like if i created an empty zip file and tried to upload it, it would give the error, but if i added any size into the file it would be successful, so yeah that was my problem, sorry for wasting ur time if u read this
Post Reply