New SIMPLE upload script not workin

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

mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

New SIMPLE upload script not workin

Post by mikegotnaild »

It will show the file being transfered. And it will go all the way through without any errors. But when i go to my ftp and look in the upload directory nothing is there. CHMOD is 777 btw. Heres the code.
form.php

Code: Select all

<?
if(!eregi("modules.php", $_SERVER&#1111;'PHP_SELF']))&#123; 
     die("You can't access this file directly..."); 
&#125; 

$module_name = basename(dirname(__FILE__)); 
$module_dir = "modules/$module_name/"; 
include("header.php"); 
$index = 1;//right sidebar or not 0=off 1=on 
title("Submit Band info/Mp3's"); 
OpenTable(); 
?> 
   <br>You may upload TWO mp3s that are no more than 3.5mb each. If one mp3 is more than
   3.5mb. You may only upload ONE. If you do not abide by this rule all information will be Discarded.
   <br>
   <FORM ACTION="http://naild.com/localmm/modules?=Bands_Showcase&file=upload" METHOD="POST" ENCTYPE="multipart/form-data"> 
   
   Browse to files:<BR>
   
   <INPUT TYPE="FILE" NAME="firstfile" SIZE="50"><BR> 
   <INPUT TYPE="FILE" NAME="secondfile" SIZE="50"><BR>
   <INPUT TYPE="SUBMIT"> 
</FORM>
<?php 
CloseTable(); 
include("footer.php"); 
?>
upload.php

Code: Select all

<?php 
 
   $uploaddir = "/localmm/upload/"; 
   $uploadfile1 = $uploaddir . $_FILES&#1111;'firstfile']&#1111;'name']; 
   $uploadfile2 = $uploaddir . $_FILES&#1111;'secondfile']&#1111;'name']; 
   
   if (!move_uploaded_file($_FILES&#1111;'firstfile']&#1111;'tmp_name'], $uploadfile1)) &#123; 
       print "ERROR: File is invalid"; 
       print_r($_FILES); 
   &#125; 

   if (!move_uploaded_file($_FILES&#1111;'secondfile']&#1111;'tmp_name'], $uploadfile2)) &#123; 
       print "ERROR: File is invalid"; 
       print_r($_FILES); 
   &#125;

?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Notice that you arn't posting direectly to upload.php so it's worth noting that uploaded files get removed if you don't move them immediately.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

im not trying to get people to write scripts for me but this is just one of those times where i need that kind of visual aid. :/ Ive been here all day trying to figure this out.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, there's one of 2 things going wrong, either the upload part just plain isn't working or the rest of the code is getting in the way..all that module stuff etc..
So i'd remove the extra code complication. Copy the example code from http://www.php.net/manual/en/features.f ... ltiple.php and run it as a totally separate file, i.e outside of your code (tweak the example to match your setup). If that works then the problem lies not in the actual uploading but in the 'surrounding code'.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

Do you mean this user submitted example from that page?

Code: Select all

<FORM ACTION="upload.php" METHOD="POST" ENCTYPE="multipart/form-data"> 
   Send these files:<BR> 
   <INPUT TYPE="FILE" NAME="firstfile" SIZE="50"><BR> 
   <INPUT TYPE="FILE" NAME="secondfile" SIZE="50"><BR> 
   <INPUT TYPE="SUBMIT"> 
</FORM> 

And in 'upload.php' have the following code: 

<?PHP 

   $uploaddir = "uploads/"; 
   $uploadfile1 = $uploaddir . $_FILES&#1111;'firstfile']&#1111;'name']; 
   $uploadfile2 = $uploaddir . $_FILES&#1111;'secondfile']&#1111;'name']; 
   
   if (!move_uploaded_file($_FILES&#1111;'firstfile']&#1111;'tmp_name'], $uploadfile1)) &#123; 
       print "ERROR: File is invalid"; 
       print_r($_FILES); 
   &#125; 

   if (!move_uploaded_file($_FILES&#1111;'secondfile']&#1111;'tmp_name'], $uploadfile2)) &#123; 
       print "ERROR: File is invalid"; 
       print_r($_FILES); 
   &#125; 

?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Yes, just tweak the upload paths etc to match your server setup.
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

so all i really need to tweak is this $uploaddir = "uploads/"; right?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

yup
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

Now im getting this error when upload is finished
ERROR: File is invalidArray ( [firstfile] => Array ( [name] => Ataris - Are We There Yet.mp3 [type] => audio/mpeg [tmp_name] => /var/tmp/phpwi03Jj [error] => 0 [size] => 1061605 ) [secondfile] => Array ( [name] => Ataris - Let It Go.mp3 [type] => audio/mpeg [tmp_name] => /var/tmp/phppGnUQr [error] => 0 [size] => 1398619 ) ) ERROR: File is invalidArray ( [firstfile] => Array ( [name] => Ataris - Are We There Yet.mp3 [type] => audio/mpeg [tmp_name] => /var/tmp/phpwi03Jj [error] => 0 [size] => 1061605 ) [secondfile] => Array ( [name] => Ataris - Let It Go.mp3 [type] => audio/mpeg [tmp_name] => /var/tmp/phppGnUQr [error] => 0 [size] => 1398619 ) )
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What does your $uploaddir = look like?
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

index.html

Code: Select all

<html>

<FORM ACTION="upload.php" METHOD="POST" ENCTYPE="multipart/form-data"> 
   Send these files:<BR> 
   <INPUT TYPE="FILE" NAME="firstfile" SIZE="50"><BR> 
   <INPUT TYPE="FILE" NAME="secondfile" SIZE="50"><BR> 
   <INPUT TYPE="SUBMIT"> 
</FORM>
</html>
upload.php

Code: Select all

<?PHP 

   $uploaddir = "/localmm/upload/"; 
   $uploadfile1 = $uploaddir . $_FILES&#1111;'firstfile']&#1111;'name']; 
   $uploadfile2 = $uploaddir . $_FILES&#1111;'secondfile']&#1111;'name']; 
   
   if (!move_uploaded_file($_FILES&#1111;'firstfile']&#1111;'tmp_name'], $uploadfile1)) &#123; 
       print "ERROR: File is invalid"; 
       print_r($_FILES); 
   &#125; 

   if (!move_uploaded_file($_FILES&#1111;'secondfile']&#1111;'tmp_name'], $uploadfile2)) &#123; 
       print "ERROR: File is invalid"; 
       print_r($_FILES); 
   &#125; 

?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If /localmm/upload/ is in your document root then you might want to try
$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/localmm/upload/';

Or is /localmm/upload/ a 'root' directory?
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

my webserver is set up like htdocs/
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

the full path would be htdocs/localmm/upload
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Sounds like you want $uploaddir = $_SERVER['DOCUMENT_ROOT'].'/localmm/upload/'; then ..

also..
put error_reporting(E_ALL); at the top of upload.php ..
<?php
error_reporting(E_ALL);
Post Reply