PHP - Automatic Upload
I want to upload a file automatically at any time from my home PC to a website I am developing. I can upload OK using a form with 'enctype="multipart/form-data"' but this requires manual operation to select a file and to submit the upload request. Is there a way the upload process can be made to happen with no operator present?
I also want to download from the website to my PC automatically ie. download a file (as it becomes available) from the website to a specified location on my PC, without operator intervention. Help. Thanks. Similar TutorialsHi everyone, I have a page that i use to upload images to my website, i got a bit fed up of uploading one at a time so i decided to add multiple file fields to the form to upload multiple images at the same time. Im having a few problems, iv read up he http://www.php.net/manual/en/features.file-upload.multiple.php and it seems all i have to do is add [] to the form names to turn them into arrays. However when i come to upload the images, i keep getting the "$error[] = "Incorrect format!...." error from the code below. I cant seem to figure out what the problem is. Could anybody please point me in the right direction? <?php session_start(); $id = $_SESSION['id']; $connect = mysql_connect("localhost","leemp5_admin","p7031521"); mysql_select_db("leemp5_database"); $query = mysql_query("SELECT * FROM users WHERE id='$id'"); $row = mysql_fetch_assoc($query); $username = $row['username']; $submit = $_POST['submit']; $type = $_FILES['image']['type']; $size = $_FILES['image']['size']; $max_size = "1000"; $width = "100"; $height = "100"; $error = array(); function make_thumb($image_name,$filename,$new_width,$new_height) { $ext=getExtension($image_name); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $source_image=imagecreatefromjpeg($image_name); if(!strcmp("png",$ext)) $source_image=imagecreatefrompng($image_name); if(!strcmp("gif",$ext)) $source_image=imagecreatefromgif($image_name); $old_x=imageSX($source_image); $old_y=imageSY($source_image); $ratio1=$old_x/$new_width; $ratio2=$old_y/$new_height; if($ratio1>$ratio2) { $thumb_width=$new_width; $thumb_height=$old_y/$ratio1; } else { $thumb_height=$new_height; $thumb_width=$old_x/$ratio2; } $destination_image=ImageCreateTrueColor($thumb_width,$thumb_height); imagecopyresampled($destination_image,$source_image,0,0,0,0,$thumb_width,$thumb_height,$old_x,$old_y); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) { imagejpeg($destination_image,$filename); } if(!strcmp("png",$ext)) { imagepng($destination_image,$filename); } if(!strcmp("gif",$ext)) { imagegif($destination_image,$filename); } imagedestroy($destination_image); imagedestroy($source_image); } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } if($submit) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $error[] = "Incorrect format! Please make sure your image is a .jpg, .jpeg, .png or .gif file."; } else { $size=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); if ($sizekb > $max_size*1024) { $error[] = "Your image is too big! The maximum upload size is 1MB."; } else { $image_name=time().'.'.$extension; $newname="uploads/" . $username . "/images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { $error[] = "There was an error uploading your image. Please try again!"; } else { $thumb_name='uploads/' . $username . '/images/thumbs/thumb_'.$image_name; $thumb=make_thumb($newname,$thumb_name,$width,$height); } } } } else { $error[] = "Please select an image to upload!"; } if(empty($error)) { echo "Upload Successfully!<br />"; echo '<img src="'.$thumb_name.'">'; mysql_query("INSERT INTO images VALUES ('','$username','$image_name','','','','','uploads/$username/images/$image_name','uploads/$username/images/thumbs/thumb_$image_name','$type','$size')"); } else { echo implode($error); } } ?> <form method="post" enctype="multipart/form-data" action="upload_images.php"> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="file" name="image[]" /><br /> <input type="submit" name="submit" value="Upload"> </form> Thanks I have code written for image uploading, but it doesn't allow multiple images on a single upload, and doesn't re-size. Anyone willing to share a good upload script that will do the following?: -Allow multiple image uploads (10+ per submission), -Re-size images on upload, and -Rename images. Thanks Brett Hi! I have a question that I need help with. I guess almost everyone of us have played a webgame where something happends automaticly. Some examples: Attacks, resources in Travian, Tribalwars, Khan Wars ... How are these things done? Now I'm talking about automatical things that happends every second. Is there a Cron Job that every second connectes to a database and adds more resources to the player? Regards Worqy <?php $files=glob('apk/*'); foreach( $files as $file) { echo '<img scr="'.$file.'">'.basename($file).'</img><br/>'; } ?> I'm trying to create a table that looks like this: 25/11/2011 28/09/2012 02/08/2013 23/12/2011 26/10/2012 30/08/2013 20/01/2012 23/11/2012 27/09/2013 17/02/2012 21/12/2012 25/10/2013 16/03/2012 18/01/2013 22/11/2013 13/04/2012 15/02/2013 20/12/2013 11/05/2012 15/03/2013 17/01/2014 08/06/2012 12/04/2013 14/02/2014 06/07/2012 10/05/2013 14/03/2014 03/08/2012 07/06/2013 11/04/2014 31/08/2012 05/07/2013 09/05/2014 Basically it formats the dates automatically every 4 weeks into 3 columns. So far, I have the following code: Code: [Select] <?php $startDate = '2011-11-25'; $columns = 3; $number_of_dates = 33; // calculate number of rows per column $rows_per_column = ceil($number_of_dates / $columns); // make your table echo "<table>\n"; //here we changed the condition to $i < $rows for($i = 0; $i < $rows_per_column; $i++) { echo "<tr>\n"; //here will run another loop for the amount of columns for($j = 0; $j < $columns; $j++) { $weekOffset = $i * 4; $nextDate = strtotime("{$startDate} +{$weekOffset} weeks"); echo "<td width = '100'>" . date('d/m/y', $nextDate) . "</td>\n"; } echo "</tr>\n"; } echo "</table>\n"; ?> Which creates the first column fine, but then repeats the same column two more times... 25/11/2011 25/11/2011 25/11/2011 23/12/2011 23/12/2011 23/12/2011 20/01/2012 20/01/2012 20/01/2012 17/02/2012 17/02/2012 17/02/2012 16/03/2012 16/03/2012 16/03/2012 13/04/2012 13/04/2012 13/04/2012 11/05/2012 11/05/2012 11/05/2012 08/06/2012 08/06/2012 08/06/2012 06/07/2012 06/07/2012 06/07/2012 03/08/2012 03/08/2012 03/08/2012 31/08/2012 31/08/2012 31/08/2012 I know that this means there is a problem with my loop resetting itself rather than continuing, but I'm not sure how to fix it. Please could someone point out my stupid mistake? Thanks Hello ,
I'm here with a problem facing with automatic login , I'm not able to login programmatically and fill the forms programatically to other website . here is the code which i have tried .
<?php I have a MySQL database that has a list of items which gets updated everyday. The database is truncated everyday and filled back with the recent posts. After it is filled out, I need an automatic system that will send out the emails to users who have provided certain keyword. I have a search query in place that will search through those posts, but I cannot figure out the email alert part. I just want to make something similar to a new job alert... What could be the potential tools that I can use to accomplish this? Currently all my website is in php. Thanks!! Hi, i am still trying to learn html and php, but i am also trying to create a website which contains a registration form. I want the validation of each field of that form to be performed automatically. So using onBlur, whenever the user steps out of a textbox field, i want to execute a php function located in another file, which will check the value of the field and display a note if the value is invalid. I want to do this using as less javascript as possible. I am not sure if what i am asking is possible but if it is i would like to know the easiest way to do this. I would appreciate any help i can get. Thanks for your time. I would like to have my site automatically email me about progress of users at certain times of the day. I am using PHP, but I think this is a server issue. I just need someone to point me in the right direction so I can search out the solution. Thank you. Hi Guy, First Post ..so please help! I have rows returning from a mYSQL Database which I put in a form which is php generated and im sending this form to the next page with a SUBMIT button. I want PHP/Javascript to do this automatically when the data is loaded from the MYSQL Table Ive tried fsockpen and document.form.submit() but it doesnt seem to work Any help. Thanks in Adv, Hittesh Ahuja <?php session_start(); if(isset($_POST['submit'])) { header("Location: http://localhost/PHP/brk_plan.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <p> <?php require_once('connect.php'); $email=$_SESSION['email']; $query="SELECT glycemic_index.gi_id,glycemic_index.value FROM food_preference JOIN glycemic_index ON glycemic_index.gi_id=food_preference.gi_id WHERE food_preference.email='$email' and glycemic_index.value >= 55 " or die("Update not Possible"); $result=mysql_query($query); $session_array=array(); echo "<form method='post' action='brk_plan.php' name='recommend'>"; echo "<p>This area is filtered from the user's table showing values only > 55</p>"; while($row=mysql_fetch_array($result)) { echo "Instead of: ".$row[0]."-".$row[1]."<br/>"; $one=$row[0]; $one_trimmed=substr($one,2,strlen($one)-5); $one_search="%".$one_trimmed."%"; $query2="SELECT glycemic_index.gi_id,glycemic_index.value,glycemic_index.food FROM glycemic_index WHERE glycemic_index.gi_id LIKE '$one_search' AND glycemic_index.value <55 AND glycemic_index.gi_id!='$row[0]' ORDER BY RAND() LIMIT 1 "; $result2=mysql_query($query2); while($row2=mysql_fetch_array($result2)) { echo "<input type='hidden' value='$row2[2]' name='fields[]'></input>"; echo "<p>You can have ".$row2[2].": ".$row2[0]."-".$row2[1]."</p>"; } } echo "<input type='submit' name='submit' value='dikha!'></input>"; echo "</form>"; //$_SESSION['higher_gi']=$session_array; //foreach($session_array as $value) //{ // echo $value."<br/>"; //} ?> </p> <p></p> <p></p> <p></p> <p></p> <p> </p> </body> </html> Hi All, Not sure if this is the right forum or not, so here goes! Just trying to generate a sitemap using: http://www.sitemapdoc.com/Default.aspx but get the error: Quote too many automatic redirections were attempted. I've a 301.php redirect file on my site to handle redirects and contains: if (isset($map[$_SERVER['REDIRECT_URL']])) { $new_loc = 'http://' . $_SERVER['HTTP_HOST'] . $map[$_SERVER['REDIRECT_URL']]; if (isset($_SERVER['REDIRECT_QUERY_STRING'])) { $new_loc .= '?' . $_SERVER['REDIRECT_QUERY_STRING']; } header("HTTP/1.1 301 Moved Permanently"); header("Location: $new_loc"); } else { header("HTTP/1.1 301 Moved Permanently"); header("Location: ".$_SERVER['HTTP_HOST']); } Is it an issue with my 301 causing the above error or something else? Many thanks is there any way to submit a form without using a submit button? I want the form to post after the user has entered a certain amount of charaters? maybe using javascript? Any help is appreciated Ant Hi all, Weird one: I am re-working a site for a client. Their old site currently grabs text from a DB and somehow automatically puts it into a <ul>. The only thing to signify a <li> is a linebreak. So if I entered: Item 1 Item 2 Item 3 into the database, they would come out looking like: Item1 Item 2 Item 3 on the site. Anyone know of a way to recreate this? An example of this in action is he http://www.postureperfection.com.au/Chairs/Amore_Chair/p/495/ (please remember - I am redesigning the site!) Thanks heaps! Hey guys! I need your help with some issues. Firstly, I have an own website with a database filled with products, and also a template page(template.php) for each product. Problem is that I don't know how to generate each product from the database in the template.php file using their id from the database. How can I do this? Second problem, I got an own checkout and I don't know how to redirect the customer to a "thank you for buying" page after clicking "Finish Order". It sends the customer to a white page where it says: "Thanks for buying!". Third and last thing, do you guys know where can I find a php checkout template to follow? Thanks in advance for your answers! Cheers! $html = @file_get_contents($urlw) or problem('Can\'t open Your Remote URL!'); $html = strtolower($html); $site_url = strtolower($set['site_url']); if (preg_match_all('/<a\s[^>]*href=([\"\']??)([^" >]*?)\\1([^>]*)>/siU', $html, $matches, PREG_SET_ORDER)) { foreach($matches as $match) { if ($match[2] == $set['site_url'] || $match[2] == $set['site_url'].'/') { $found = 1; if (strstr($match[3],'nofollow')) { $nofollow = 1; } break; } } } if ($found == 0) { echo "<center><h2>Our URL Not FOund on your page please submit or check again</h2></center>"; } else next proceggerr.... in $html we getting the content of that page which that user give where he put our link what is this actually this all code is doing infact i was making a link exchange site where on a page people can submit their link for exchange and give their site link and the that page link where they have put our link this code verify at the sPot did they have put our code or not but m facing some problem.. beacuse it's not working good Hi there, I am working on a php project on my WAMP server where I have access to XML datafeed from xe.com once a day to get the Exchange rates. This xml datafeed is saved on my localhost as an archived copy. Now I would like to automatically access the fresh xml datafeed file from xe.com once a day and replace (or update) the xml file on my localhost to have the updated information (rates). How can I schedule this task automatically and make php access the updated xml file once a day. All comments and feedbacks are always welcomed Thank you! Hello, I have a website designed in simple php http://www.fsbizcollect.com/. It has a wordpress blog installed under sub-directory called "business-debt-collection-agency-blog" To query posts from blog on home page, I am using: <? foreach($sql->select("wp_posts", "where post_status = 'publish' order by post_date desc limit 3") as $row){ ?> <div class="bEntry"> <h2><?= $row['post_title'] ?></h2> <h3><?= date('F j, Y', strtotime($row['post_date'])) ?></h3> <p> <?= $row['post_excerpt'] ?> <a href="<?= $row['guid'] ?>">Read More</a></p> </div> <? } ?> It is working fine. I want to put post thumbnails on homepage. Post thumbnail should be automatically resized to width=110px and will be placed in : <div class="blogThumb"> POST THUMBNAIL PHP SCRIPT WILL COME HERE </div> Could anyone provide php script for this? Thank you Ok, so can someone edit this code: Code: [Select] <center> <table height="300px" bgcolor="#FFFF00" cellspacing="1" width="75%"> <tbody> <tr> <td> <table height="433" bgcolor="#000000" cellpadding="10px" cellspacing="1" width="995"> <tbody> <tr> <td bgcolor="#000000" valign="top" width="20%"> <div id="menu" align="right" > <a href="/forums/index.php">HOME</a> | <a href="mailto:xxxxxxx@trigamer.com">CONTACT</a> | <a href="">ABOUT (soon)</a> </div> <?php $fid = $_GET['fid']; require "global.php"; if ($_POST) { if (! trim($message) ) { // message is blank } $user = $_POST['user']; $password = $_POST['password']; $message = $_POST['message']; $title = $_POST['title']; $date = time(); $data = sprintf("INSERT INTO threads (tid, fid, title, user, dateline) VALUES (DEFAULT, $fid, '$title', '$user', $date)"); mysql_query($data); $tid = mysql_insert_id(); $data = sprintf("INSERT INTO posts VALUES (DEFAULT, $tid, '$user', '$message', $date)"); mysql_query($data); header( 'Location: replythread.php?tid='.$tid ); exit; } echo ' <font size=5><b>Add a New Post:</b></font> <form action="" method="POST" name="formpost" onsubmit="return validate();"> <table> <tr><td>Username:</td><td><input name="user" /></td></tr> <tr><td>Password (optional):</td><td><input type="password" name="password"></td></tr> <tr><td>Post Title:</td><td><input name="title" /></td></tr> <tr><td valign="top">Message: </td><td><textarea rows="10" cols="50" name="message"></textarea></td></tr> </table> <input type="submit" value=" Add new post " /> </form>'; ?> </td></tr></tbody></table></td></tr></tbody></table><br /> </center> <script> function validate() {return true; } </script> So that a tickable box can be beside "Post title" to the right of the text box that says, "Review," so that when a post is made, it will have "Review:" before the post title on the forum? Here is what the code above shows you: And this is what I want it to look like on the forums: Thanks! So basically I have a database full of players 'items'. Each player has 2 items. and I need to make a circle with these players with only specific items involved. Each circle can only contain 6 players. The items needed to create this circle a pigs spice sugar cows aluminium marble iron lumber wheat water random random so 10 resources are literally needed to create this circle but 12 is needed to make it a 'circle' if you get me. I'd like to note that it is possible that any of these players can have a combination of any of resources listed above. I've created a form that allows people to submit players resources into my mysql database. I heard it was possible that I could code some type of filter/sort code to sort out the players resources from my database automatically into a set that will match what is needed (without any repeat of resources) and having a php code to export it into html format for viewing pleasures. I really have no idea how to go about this in mysql or php. But if somebody could help me out i'd be ever so glad. Also to note: this isn't school work or something. It's from a game I play and i'm just trying to make my job in it easier. I was thinking of maybe a php code that will run through all the possible partners in order to create this set like run through 100s of different sets until the required set is obtained. I heard this is just about possible. Can anyone help me? Looking forward to all the great help around here. Thanks Samuz PS: Each item/resource can only appear once in each circle. Hi again PHPFreaks
I'm building on my new local project in which I wish to create a working function for a future e-commerce. But I ran into a problem.
Please open following picture in order for me to illustrate my problem. http://i1227.photobu...zpsacd52b0c.jpg
The picture represents what I want. My only problem is that I have no idea how to make the "Total price:" value (which is 1.2€ on the picture) to match the quantities above.
Lets say a costumer chose 10 quantities - in that case i would like it to automaticly change the total price value to 12€ instead, so that it matches the amount of quantities chosen.
How would i be able to do this?
Thx in advance
- r e c 0 i l
|