PHP - Problem In Date Subtraction After Uploading
hi, i am working on an assignment in which i am getting current date and then getting date of two previous months i.e
2010-09 2010-08 2010-07 the problem is that the code is working perfectly on localhost but when i upload the file it only shows the current date and do not subtract and display dates. can some body guide me that what is the problem and how to solve it. here is the code $date1= date("Y-m"); $date2 = strtotime ( '-1 month' , strtotime ( $date1 ) ) ; $date2 = date ( 'Y-m' , $date2 ); $date3 = strtotime('-1 month', strtotime( $date2 ) ); $date3 = date( 'Y-m' , $date3); ?> <select name=""> <option><?php echo $date1; ?></option> <option><?php echo $date2; ?></option> <option><?php echo $date3; ?></option> </select> Similar TutorialsHello, I am running this script: Code: [Select] while($row = mysql_fetch_array($query)) { $compare_points_1 = $row['sideone_points']; $compare_villages_1 = $row['sideone_villages']; $compare_members_1 = $row['sideone_members']; $compare_points_2 = $row['sidetwo_points']; $compare_villages_2 = $row['sidetwo_villages']; $compare_members_2 = $row['sidetwo_members']; } $point_1 = $_POST['points_1']; $village_1 = $_POST['villages_1']; $member_1 = $_POST['members_1']; $point_2 = $_POST['points_2']; $village_2 = $_POST['villages_2']; $member_2 = $_POST['members_2']; $points_1_calc = $compare_points_1 - $point_1; $villages_1 = $compare_villages_1 - $village_1; $members_1 = $compare_members_1 - $member_1; $points_2 = $compare_points_2 - $point_2; $villages_2 = $compare_villages_2 - $village_2; $members_2 = $compare_members_2 - $member_2; When I try to output $points_1_calc it gives me: -100 It will Add & Times & Divide but not Subtract. Everything fills with Numbers only and I've tried this seperately and it works on a different script where I manually put in the numbers. All variables fill with numbers as I have a part above that doesnt go through if there is nothing to compare against. Any help would be greatly appreciated. This should be simple. However, when I run the script and input a say 18 char long string, it still returns -10. The variable char_total is accurately capturing the string length. Code: [Select] <?php $inputid = $_POST['steamid']; $steam_prefix = substr($inputid, 0, 10); $prefix_length = 10; $steam_suffixchars = ($char_total - $prefix_length); $char_total = strlen($inputid); if($char_total > 25 || $char_total < 11) $char_valid = false; else $char_valid = true; if($steam_prefix === "STEAM_0:1:" || $steam_prefix === "STEAM_0:0:") $prefix_check = true; elseif($steam_prefix != "STEAM_0:1:" || $steam_prefix != "STEAM_0:0:") $prefix_check = false; echo "$steam_suffixchars" ?> I am having trouble getting my upload file to work... Form HTML: Code: [Select] <form action="" method="POST"> <input type="file" name="file" /> <input type='"submit" name="upload" value="Upload" /> </form> PHP: Code: [Select] if($_POST["upload_avatar"]){ $upload_path = "images/users/"; $file = $_FILES["file"]["name"]; $extension_types = array("gif","jpg","jpeg","png"); if($file){ $filename = stripslashes($_FILES["file"]["name"]); $extension = getExtension($filename); $extension = strtolower($extension); $size = filesize($_FILES["file"]["tmp_name"]); if(in_array($extension, $extension_types)){ if($size <= $max_file_size){ $file_search = glob($upload_path . strtolower($username) . '*'); array_map("unlink", $file_search); $file_name = $upload_path . strtolower($username) . "." . $extension; $copied = copy($_FILES["file"]["tmp_name"], $file_name); if (!$copied){ $r_error = "Upload has failed"; } } else{$r_error = "File too big";} } else{$r_error = "Unknown file extension";} } else{$r_error = "No file chosen";} } Every time, it gives me the "No File Chosen" error. It doesn't seem to be actually uploading the file... I hope this isn't just some stupid thing I am looking over, can someone help me? Hi, I have a strange problem with uploading files. My script was working fine on the test server but since moving to the live server it isn't working. Here is a printout of the FILES variable: Code: [Select] Array ( [file] => Array ( [name] => filename.ppt [type] => [tmp_name] => [error] => 1 [size] => 0 ) ) Does anyone know what the problem might be? The error message that comes back is 'Invalid file'. Code: [Select] function upload_ppt_files() { echo 'print_r($_FILES) = '.print_r($_FILES).'<br />'; global $CFG; if (($_FILES["file"]["type"] == "application/vnd.ms-powerpoint") && ($_FILES["file"]["size"] > 100)) { if ($_FILES["file"]["error"] > 0) { $CFG->message = "Error code:". $_FILES["file"]["error"]; manage_ppt_files(); } else { if (file_exists("../../uploads/" . $_FILES["file"]["name"])) { $CFG->message = $_FILES["file"]["name"] . " already exists."; manage_ppt_files(); } else { move_uploaded_file($_FILES["file"]["tmp_name"], "../../uploads/" . $_FILES["file"]["name"]); $CFG->message = "File uploaded successfully."; manage_ppt_files(); } } } else { $CFG->message = "Invalid File."; manage_ppt_files(); } } This is my PHP code which uploads the image from a html form. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Upload a Photograph</title> <link rel="stylesheet" href="uploadify.css" type="text/css" /> <script language="JavaScript" type="text/javascript"> <!-- function breakout_of_frame() { // see http://www.thesitewizard.com/archive/framebreak.shtml // for an explanation of this script and how to use it on your // own website if (top.location != location) { top.location.href = "http:/noltest.lib.siu.edu/drupal/blincore?file='"+fileObj.name+"'" ; } } --> </script> <script type="text/javascript" src="jquery-1.3.2.min.js"></script> <script type="text/javascript" src="jquery.uploadify.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#fileUpload").fileUpload({ 'uploader': 'uploader.swf', 'cancelImg': 'cancel.png', 'script': 'upload.php', 'folder': 'downloads', 'fileDesc': 'Image Files', 'fileExt': '*.jpeg,*.jpg,*.tif,*.tiff,*.gif,*.png', 'checkScript': 'check.php', 'multi': false, 'displayData': 'speed', 'onComplete': function(event, queueID, fileObj, response, data) { $('#filesUploaded').append ('One Image Uploaded successfully (<a href='+fileObj.filePath+'>'+fileObj.name+'</a>)</br></br> <FORM METHOD=POST ACTION="http://nol.lib.siu.edu/drupal/dublincore"> <INPUT NAME=filename value="'+fileObj.name+'"> <INPUT TYPE=submit VALUE="NEXT" ></FORM ><br>');} }); }); </script> </head> <body style="background: #f1ede0 url(http://nol.lib.siu.edu//sites/all/themes/admire_grunge/images/bg2.jpg) repeat fixed top center;"> <h2>Single Photograph Upload</h2> <div id="fileUpload">Issue with your javascript</div> <a href="javascript:$('#fileUpload').fileUploadStart()">Start Upload</a> | <a href="javascript:$('#fileUpload').fileUploadClearQueue()">Clear Queue</a> <p></p> <p><div id="filesUploaded"></div></p> </body> </html> problem: when i try to upload image from the desktop which contains image named (test.jpg) , this test.jpg is not shown when browsing to select the image file. any advice... hi guys... I'm resizing image with some script. it works fine. but some times it gives following error and make image black. either it should not upload/resize image or it should do that for all. following is the error list i found on some images Code: [Select] Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/large/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/thumb/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/medium/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '../../../directory/images/xlarge/0419063.jpg' is not a valid JPEG file in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 49 Warning: imagesx() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 34 Warning: imagesy() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 35 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 182 Warning: Division by zero in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 183 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 76 Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 77 Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in C:\Program Files\VertrigoServ\www\demo\administrator\modules\directory\classes\resize-class.php on line 201 hi i m new to php there is two basic script i m testing on my localhost but it gives me error "( ! ) Notice: Undefined index: video in C:\wamp\www\Boysjoys\video\upload.php on line 4" "( ! ) Notice: Undefined index: video in C:\wamp\www\Boysjoys\video\upload.php on line 16" "( ! ) Notice: Undefined index: video in C:\wamp\www\Boysjoys\video\upload.php on line 27" i cant find where is the real problem is ##########FORM########### <form name="upload" action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="video"> <input type="submit" value="UPLOAD"> </form> #########FORM############ #########PHP############# <?php // This is the directory where images will be saved $path="uploaded/"; $path=$path.basename($_FILES["video"]["name"]); //This gets all the other information from the form $video=$_FILES["video"]["name"]; //connect to database $con=mysql_connect("localhost","root","") or die (mysql_error()); //SELECTING THE DATABASE mysql_select_db("admin_bj",$con) or die(mysql_error()); //write information to the database mysql_query("INSERT INTO 'video'(video) VALUES('$video')"); //write file to server if(move_uploaded_file($_FILES["video"]["tmp_name"],$path)) { // execute if all is ok echo "the file " . basename( $_FILES['uploadedfile']['name']). "has been uploaded and your information has been added to the server"; } else { //GIVES AND ERROR IF ITS NOT OK echo "Sorry,there was a problem in uploading."; } ?> #########PHP############# I have a php website with two parts the client part and an admin part in the client part or the viewers end , i need to show the details of products with description and an image (in the front page). The details are entered though the admin part. My problem is the image uploaded goes to the folder in the admin folder but in the home page the images are taken from the images folder suitated in outside the admin folder . How can i upload images or photos to the folder outside the admin though the admin pages. Pasting my code here Code: [Select] $target = "pics/"; [color=red]//this is created in the admin folder, i need to change here that is keep the folder outside the admin folde[/color]r $target = $target . basename( $_FILES['photo']['name']); $pic=($_FILES['photo']['name']); $image=$pic; $box_num =$_POST['box_num']; $query11 = "update photo_table set page_head='$page_head',image='$image' where id='$box_num'"; $result11 = mysql_query($query11); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } }else { echo "Sorry, there was a problem uploading your file."; } } } Hi All, I have been having issues for several days uploading a simple pdf file via Curl to one of our service providers servers. I'm doing an is_uploaded_file check and getting a successful response, but the document is not actually being uploaded to the server. Can anyone help?? Please see code below: Code: [Select] $filename = $_FILES['activity_doc']['name']; // Name of the file (including file extension). $upload_path = https://upload_url //Curl session initialized $session = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($session, CURLOPT_URL, $upload_path); curl_setopt($session, CURLOPT_USERPWD, 'username:password'); curl_setopt($session, CURLOPT_POST, 1); $post = array( "file_box"=>"@" . $filename, ); curl_setopt($session, CURLOPT_POSTFIELDS, $post); $response = curl_exec($session); if (is_uploaded_file($_FILES['activity_doc']['tmp_name'])) { echo "File ". $_FILES['activity_doc']['name'] ." uploaded successfully.\n"; } else { echo "Error occurred, file uploaded unsuccessful"; } $req = new SimpleXMLElement($response); print_r($req); curl_close($session); I have created a page for users to upload files, but for some reason end users can't access the files. we are getting an access denied page and every time files get uploaded i have to ftp to the site and change the permissions. is there something i am missing? Thank you in advance. I developped a cms system to upload images with php to a mysql database and a upload folder on the server. Firefox version 5.0.1 for MAC and earlier have no problems with uploading through the script. But after that version it is impossible to upload images bigger then 250kb. The page where the customer chooses his image for upload stalls and the form is not sent to the actual upload script, which should validate and process the image. This problem only occurs in Firefox, all other browsers work just fine! I tried to run the same script with Firefox on a PC and everything works fine. So it is a Mac related problem. You can try for yourself to see what happens in the following basic script (if you don't get a succes message it means that you are still hanging on the image_upload page and nothing has happened) : http://siteways.net/test_upload/image_upload.php I'm working on a portal project for a school and they make weekly flyers like the one attached below. Now if the file attaches to this post, then at least I know some script changes will fix the problem. The school has an archive of hundreds of these docs they'd like to load up, so I need a solution. I've made many versions of my upload script, which have been working fine for any word documents I create, but not for their word docs. This is the code in my latest version. Code: [Select] <?php require("checkpass2.php"); require("../teacher/checkpass.php"); require("../access.inc.php"); mysql_connect("$host","$login","$pass") OR DIE ("There is a problem with the system. Please notify your system administrator." .mysql_error()); mysql_select_db("$db") OR DIE ("There is a problem with the system. Please notify your system administrator." .mysql_error()); include("../commonsettings.php"); IF ($_POST['upload']){ //$directory="$siteurl"; $directory=".."; $section=$_POST['section']; $directoryname = preg_replace('/[^a-zA-Z]/', '', $section); $directlevel="$directory/$directoryname"; if(!file_exists($directlevel, 0777)) { mkdir($directlevel); } $target_path = "$directlevel/"; $loaddate = date('MY'); $filename = preg_replace('/\s+/', '', $_FILES['uploadedfile']['name']); $file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention $file_ext = substr($filename, strripos($filename, '.')); // strip name $filesize = $_FILES["uploadedfile"]["size"]; if (($file_ext == ".doc" || $file_ext == ".docx") && ($filesize < 200000)) { // rename file $newfilename = $file_basename."_Uploaded_".date('M-Y') . $file_ext; $nfilename = $newfilename; if (file_exists($target_path . $newfilename)) { unlink($target_path . $newfilename); mysql_query("DELETE FROM ".$conf['tbl']['uploads']." WHERE filename='$nfilename' AND section='$directoryname'") or die(mysql_error()); } if (!file_exists($target_path . $newfilename)) { move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $target_path . $newfilename); $result = mysql_query("INSERT INTO ".$conf['tbl']['uploads']." SET filename='$nfilename', section='$directoryname'") or die(mysql_error()); header("Location:UploadFiles.php"); } } elseif (empty($file_basename)) { // file type error header("Location:UploadFiles.php?error=1"); } else { // file selection error header("Location:UploadFiles.php?error=2"); } } ?>Any help greatly appreciated. [attachment deleted by admin] When I upload files > 2MB, I get an "Internal Server Error" and in the errors log see "Premature end of script headers:..." No problem with smaller files. I'm running PHP 5.28 and have the following in php5.ini. magic_quotes_gpc = Off log_errors = on display_errors = off memory_limit = 64M post_max_size = 8M upload_max_filesize = 8M max_input_time = 360 max_execution_time = 360 upload_tmp_dir = amd_temp The permissions for the upload folder are set to 755. Here's the code: <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') { ?> <form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" enctype="multipart/form-data"> <input type="file" name="document"/> <input type="submit" value="Send File"/> </form> <?php } else { if (isset($_FILES['document']) && ($_FILES['document']['error'] == UPLOAD_ERR_OK)) { $newPath = 'updocs/' . basename($_FILES['document']['name']); if (move_uploaded_file($_FILES['document']['tmp_name'], $newPath)) { print "File saved in $newPath"; } else { print "Couldn't move file to $newPath"; } } else { print "No valid file uploaded."; } } ?> Any thoughts on what might be the problem? Thanks. We have a website that allows the user to upload his/her picture so we use the ftp_put() command. I use Code: [Select] <?php $path = getcwd(); echo $path; ?> This is the output: Code: [Select] /home/vol10/000a.biz/a000b_7363341/htdocs/gankgame to determine the absolute path where my website is stored. My website "CAN" connect to the ftp server but it can't upload files. Uploading always fail. I can't determine the right path. "My code is attached" We are using a FileZilla server for our upload ftp server and we encountered a problem in uploading files. When we upload files 1KB - 1.5MB it will be a success but when we upload a file higher than that an error says: "Filename cannot be empty in C:\wamp\www\gankgame\myaccount.php on line 53" Furthermore, when we upload a file much greater than that like 30MB+ it will not upload but has no errors. Is there any way to configure the upload maximum size? or to fix this errors ? Help us please Our upload code is uploaded . please see the attachment hello guys, i need a help from u. from past 1 week , i am searching for it. may be it is simple query for you . in my project, i am uploading a file, for example 5mb of audio file, while uploading i need to display a progress bar along with percentage of how much it is uploaded to server ( as it works in google chrome browser). i tried several codes by searching in google . No code is working. i can able to display only loader.gif image not the status bar with percentage. so pls guys if you have these codes, pls share it . |