lindm Posted September 11, 2007 Share Posted September 11, 2007 I am trying to create an upload script that performs the following: 1. Uploads to the file to the same directory as the upload.php script (right now it uploads to root it seems..) 2. Renames the file to xxx.txt (no function for this yet) 3. If xxx.txt exists it replaces this one (no function for this yet) 4. Limits import by file extensions (.se and .sie) (no function for this yet) Found some beginning code on the internet and here is my result so far: <?php $target = "/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 100000) { echo "Your file is too large.<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> Any help to complete much appreciated. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 You need to tell us what the problem is. What doesn't happen that you want it to, and what have you tried besides copying this big chunk of code. Quote Link to comment Share on other sites More sharing options...
lindm Posted September 11, 2007 Author Share Posted September 11, 2007 Alrighty...as a newbie I need to find a way (function) to change the name of the file to for instance xxx.txt and if the file already exists replace the existing file. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 There are lots of ways. Did you check the manual? http://www.php.net/manual/en/ref.filesystem.php If you go to php.net and search for something it will tell you what functions there are. Try looking up rename, since that's what you want to do. Quote Link to comment Share on other sites More sharing options...
lindm Posted September 12, 2007 Author Share Posted September 12, 2007 Hello again, What I am now trying is modifying my existing import script. I have (with help of course) created two functions that import data from an external file. What I am trying is to make the $contents (below) read the file that a user specifies in a separate form on a separate html page. In other words: 1. User is on form.html. User browses local drive and selects a file. 2. Form.html is submitted to import.php which contains the script below. $contents = file('file.txt'); foreach($contents as $line_value) { list($cat, $int, $id, $num) = explode("\t", $line_value); $cat = str_replace('#', '', $cat); $number[$cat][$int][$id] = trim($num); } //SIE FÖR ATT SUMMERA function calculate_range($cat, $bool, $range_min, $range_max) { global $number; $total = 0; for($i = $range_min; $i <= $range_max; $i++) { if(isset($number[$cat][$bool][$i])) { $total += $number[$cat][$bool][$i]; } } return $total; } Quote Link to comment Share on other sites More sharing options...
lindm Posted September 12, 2007 Author Share Posted September 12, 2007 Is this correct? $contents = $_FILES['userfile']['name']; Quote Link to comment Share on other sites More sharing options...
lindm Posted September 12, 2007 Author Share Posted September 12, 2007 Got it now: $contents = file($_FILES['userfile']['name']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.