Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
thundarfoot
Regular
Regular



Joined: Jan 16, 2008
Posts: 75

PostPosted: Thu Jan 24, 2008 5:16 pm Reply with quote

I hope someone here can help with this (I have allready recived quite a lot of help here so here goes)

I have a working php script to upload files, I am trying to turn it into a module or block or whatever to work inside nuke. this will be the second app I have done this with so I am big time noob.

I am not sure why its not working, no matter what file is uploaded I get the error "file already exists"

this form code was placed in the editor and saved as a block.

Code:
<form action="modules.php?name=uploads" method="post" onsubmit="this.submit.disabled='true'">

    <input type="hidden" name="MAX_FILE_SIZE" /> Choose a file to upload: <input type="file" name="uploadedfile" /><br />
    <input type="submit" value="Upload File" />
</form>


Here is the code which is located in modules/uploads/index.php

Code:
<?php

if (!defined('MODULE_FILE')) die('You can\'t access this file directly...');
require_once('mainfile.php');
require_once('../LootWhore/Connections/Lw.php');
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = '- You Module Name'; // If you need this to be multi-lingual then you will have to use language defines
include_once 'header.php';
OpenTable();

// Where the file is going to be placed
$target_path = "D:/";

/* Add the original filename to our target path. 
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name']; 

$target_path = "D:/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(file_exists($target_path)){
echo "File already exists";
} else {
  if(strrchr($_FILES['uploadedfile']['name'], ".") != ".zip"){
    echo "only zip files are allowed";
  } else {
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }
  }
}
?>


I would prefer the whole scrip be on one page in a module, but I dont know how do do that yet. I thought I new how to run a select form from a block to call a module....but not quite I guess, any help is much appreciated.

[/quote]
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Thu Jan 24, 2008 6:05 pm Reply with quote

It does the file exist check here
Code:


$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(file_exists($target_path)){
echo "File already exists";


So $target_path must be returning the same value every time.

_________________
- Only registered users can see links on this board! Get registered or login! -

Need help? Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
thundarfoot







PostPosted: Thu Jan 24, 2008 6:17 pm Reply with quote

ty I have it working now as a single page module just as I wanted.
 
flintman
New Member
New Member



Joined: Jan 09, 2007
Posts: 13

PostPosted: Sun Mar 02, 2008 8:27 pm Reply with quote

I tried this but doesn't work. Im action using it on the admin side
Code:
<INPUT type =\"file\" NAME=\"userfile\" id=\"userfile\"> </P>

         <P><strong>Info About Trailer</strong><br>
          <TEXTAREA NAME=\"info\" COLS=50 ROWS=5 WRAP=virtual></TEXTAREA></p>
          <P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"ADD\"></p>
          <input type=\"hidden\" name=\"op\" value=\"trl4saleGoSave\"
          </FORM></center>";
   
         include ('header.php');
         Opentable();
         GraphicAdmin();
         echo $block;
         Closetable();
         include ('footer.php');
         
         }
      
         Function trl4saleGoSave($id, $price, $condition, $size, $door, $tire, $axle, $info)
         {   
          
           global $prefix, $db, $admin_file, $_FILES;
    
             $uploaddir = "modules/forsale/pics/";

      ///Define the file
        $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
      $filename= $_FILES['userfile']['name'];
$db->sql_query("insert into pic VALUES ('$id','$filename','$price','$info','$condition','$size','$door','$tire','$axle')");

      //ECHO $filename;

      $extension = substr (strrchr ($uploadfile, "."), 1);
      


///Checks to see if file has been uploaded and then gives message accordingly.
           if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
         {
               $msg = "File is valid, and was successfully uploaded.\n";
           }
         else
         {
            include ('header.php');
               Opentable();
               GraphicAdmin();           
               echo "DIDN'T TAKE!\n";
               Closetable();
               include ('footer.php');
           }
           
         }

Sorry for the long code but the HTML code is in one function then when i switch to another function I don't have access to $_FILES. I have it Global also.
 
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©