Jump to content

B34ST

Members
  • Posts

    94
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

B34ST's Achievements

Member

Member (2/5)

0

Reputation

  1. I figured it out: $file_name = $HTTP_POST_FILES['ufile']['name']; $new_file_name=$_POST['name']; if($ufile !=none) { echo "Successful<BR/>"; echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; $zip = new ZipArchive(); $filename = 'uploads/'.$new_file_name.'.zip'; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } $zip->addFile($file_name); $zip->renameName($file_name, $new_file_name); echo "numfiles: " . $zip->numFiles . "\n"; $zip->close(); } Thanks anyway
  2. I am trying to make a script so that a user can upload a file, however I need to rename the file and add it to a zip. At the moment I am uploading the file to my server then renaming it, then adding it to a zip and then deleting the original uploaded file. is there a better way of just putting it straight in the zip with the new name? here is my code: <?php if (!$_POST) { echo '<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td><strong>Single File Upload </strong></td> </tr> <tr> <tr> <td>Name:</td> <td><input type="text" size="16" name="name"></td> </tr> <td colspan="2">Select file <input name="ufile" type="file" id="ufile" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table>'; } else { $file_name = $HTTP_POST_FILES['ufile']['name']; $new_file_name=$_POST['name']; $path= "uploads/".$new_file_name; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; $zip = new ZipArchive(); $filename = 'uploads/'.$new_file_name.'.zip'; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } $zip->addFile($path); echo "numfiles: " . $zip->numFiles . "\n"; $zip->close(); unlink($path); } else { echo "Error"; } } } ?> Also when the zip is packed it is packing the file into an uploads directory instead of the root of the zip, how can I solve this? Thanks
  3. Ah now I see, No I did not know that I could add two unique keys at the same time. When I tried to do them seperately I was given an error but now trying it your way has worked and now so does the on duplicate key statement. Thanks for all the help.
  4. The table will not let me put a unique key on username and skill because the username should be inserted on 29 rows. however adding a last_updated column isnt a bad idea, this could help with identifying non active members. thanks for the help. I will leave this topic as unsolved for now although this "cheat" will solve my problem it would still be nice to know if there is another way around this.
  5. I tried using on duplicate key but again it does not achieve what i need as it only works on a primary or unique key. I cannot use the primary key as this an auto_increment value. and I cannot set the field to be unique because there will be multiple entries the same for example for each user there will be 29 different skills so i must use both username and skill in the mysql WHERE statement. here is an example of the table: id | username | skill | rank | level |experience 1 | user1 | skill1 | 1 | 99 | 200000 2 | user1 | skill2 | 3 | 93 | 100000 3 | user2 | skill1 | 5 | 94 | 50000 4 | user2 | skill2 | 7 | 98 | 20000
  6. Hi I am trying to update a table if an entry already exists or insert a new entry if it does not. I have the following: $sql = $conn->query("UPDATE rs_stats SET rs_rank='$stats[0]', level='$stats[1]', experience='$stats[2]' WHERE username='$user' AND skill='$skill[$i]'"); if ($conn->affected_rows == 0) { $sql = $conn->query("INSERT INTO rs_stats (username, skill, rs_rank, level, experience) VALUES('$user', '$skill[$i]', '$stats[0]', '$stats[1]', '$stats[2]')"); } The above works fine unless the data stays the same. I think this is because $mysqli->affected_rows only returns a 1 if the row was actually changed but if the row exists and all data is the same it returns a 0. I would like to know how to find out how many matches there where instead? If i use mysqli->info it returns this and i could use preg_match to see if it a 1 or a 0 but this seems to be a long way of doing it. any ideas? any help appreciated Thanks
  7. thank you rhodesa that works perfectly
  8. In the past I have tried smarty and other template engines in the past however although smarty is a great templating sytem I just find it too large for my needs. If i can fix the above problem I will have a templating system which suits me perfectly and is only 40 lines of code.
  9. Hi, recently I have been trying to write a template class and found a great start on codewalkers.com I can replace tags but the problem is when i am trying to replace tags in a loop, here is what I have : snippet form template class: function get_block($block) { preg_match ('#<!-- START '. $block . ' -->([^*]+)<!-- END '. $block . ' -->#',$this->page,$this->return); $code = str_replace ('<!-- START '. $block . ' -->', "", $this->return[0]); $code = str_replace ('<!-- END ' . $block . ' -->', "", $code); return $code; } function replace_block_tags($blockname, $data) { $blockCode = $this->get_block($blockname); foreach ($data as $key => $value) { $blockCode = str_replace ("{".$blockname.".".$key."}", $value, $blockCode); } $this->page = str_replace ($this->return[0], $blockCode.$this->return[0], $this->page); } index.php: $sql = "SELECT * FROM users"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $page->replace_block_tags("users_block",array( "user_id" => $row['user_id'], "username" => $row['username'], "email" => $row['email'])); } index.tpl: <table> <!-- START users_block --> <tr> <td>{users_block.user_id}</td> <td>{users_block.username}</td> <td>{users_block.email}</td> </tr> <!-- END users_block --> </table> This works fine however it always adds an extra row for example: 1 user 1 email 1 2 user 2 email 2 {users_block.user_id} {users_block.username} {users_block.email} how can I remove or hide that last row? thanks for any help
  10. Hi i have been using the jquery.form plugin for jquery to create a form within a modal dialog. I can do this succesfully and process the form afterwards however i want to use multiple dialogs on the same page. here is the javascript i am using <script type="text/javascript"> $(document).ready(function() { $('#layer1').Draggable( { zIndex: 20, ghosting: false, opacity: 0.7, handle: '#layer1_handle' } ); $('#layer1_form').ajaxForm({ target: '#content', success: function() { $("#layer1").hide(); } }); $("#layer1").hide(); $('#user_info').click(function() { $("#layer1").show(); }); $('#close').click(function() { $("#layer1").hide(); }); }); </script> with this html: <div id="content"><a href="#" id="user_info">edit</a></div> <div id="layer1"> <div id="layer1_handle"> <a href="#" id="close">[ x ]</a> User information </div> <div id="layer1_content"> <form id="layer1_form" method="post" action="save_settings.php"> Username<input type="text" name="username" /><br /> <input type="submit" name="submit" value="Save" /> </form> </div> </div> I can get multiple dialogs to work by simply adding the same javascript and html with different id's e.g. layer2 I was wondering if there was an easier way to do this for example maybe use a wildcard number at the end so it will look for layer and can then pass any number after that as an id to display the relevant form? I can easily duplicate the html side by using a for loop in php grabbing the relevant form details from my db but i am trying to avoid having to duplicate the js for each dialog. thanks for any help in advance
  11. While I was waiting for a reply I decided to have a closer look at smarty and I think I will try to implement this system. As you say overkill is nothing I guess Im just being picky. Thanks again for your help.
  12. In that case you might not be aware that you can have as many as you like (at least i am not a aware of any limitations) example: index.php?mode=edit_post&uid=4&post=123 Yes this is a great community with a lot of knowlegeable members.
  13. You can use something like the following url: index.php?mode=edit_post&post=123 then retrieve the data: $mode = $_GET['mode']; $post = $_GET['post'];
  14. Hi, thanks for the reply. I have heard of smarty and thought about using it but isnt it more advanced than the phpbb way? At the moment the phpbb way is overkill so I think the smarty template system will also be overkill for what I require? As I said in a previous post I only need to pass the variables and loops into the template. Or would it be best to have the more adbanced script for future modifications?
  15. try this instead <?php include "config.php"; $query="SELECT story_title, story_num FROM data order by story_num desc limit 5"; $result=mysql_query($query); $i=0; while($row = mysql_fetch_array($result)) { $story_title = $row['story_title']; $story_num = $row['story_num']; $story_note = $row['note']; if ($story_note==1) { echo "<img src='images/notice.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>"; $i++; } elseif ($story_note==2) { echo "<img src='images/updated.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>"; $i++; } elseif ($story_note==3) { echo "<img src='images/event.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>"; $i++; } elseif ($story_note==4) { echo "<img src='images/important.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>"; $i++; } else { echo "<img src='images/notice.png'> <a href='show_story.php?story_num=$story_num'><font color='white' size='2'>$story_title</font></a><br><br>"; $i++; } mysql_close(); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.