PHP - Strange Fopen Problem
Hi,
I was using latest php5 but as I couldn't find a ffmpeg-php extension for it, I actually swapped to latest php4, and now I'm having a problem when using fopen for urls, when it's used it just stops the script with no error / warning, i tried using the same php.ini used with my php5 too but it changes nothing. Btw allow_url_fopen is enabled. Thanks if someone can help. Similar Tutorialshi, I want to write pdf file but it is getting garbage value i check following url http://bugs.php.net/bug.php?id=21904&edit=1 Code: [Select] $fp = fopen($fdirandname,'wb'); fwrite($fp,$pdfcode); fclose($fp); Hi, I am modding phpBB3 and I want to make the contents of a text documents appear in a border. This is what I have in my portal_style.html: Code: [Select] <!-- INCLUDE overall_header.html --> <?php $a1=fopen("/port/announce/announce1.txt", "r"); $a2=fopen("/port/announce/announce2.txt", "r"); $a3=fopen("/port/announce/announce3.txt", "r"); $a4=fopen("/port/announce/announce4.txt", "r"); $a5=fopen("/port/announce/announce5.txt", "r"); ?> <h2>Announcement!</h2> <div class="panel"> <div class="inner"><span class="corners-top"><span></span></span> <div class="content"> <?php echo $a1; ?> </div> <span class="corners-bottom"><span></span></span></div></div> <h2>Announcement!</h2> <div class="panel"> <div class="inner"><span class="corners-top"><span></span></span> <div class="content"> <?php echo $a2; ?> </div> <span class="corners-bottom"><span></span></span></div> </div> <!-- INCLUDE jumpbox.html --> <!-- INCLUDE overall_footer.html --> Anyone mind showing me how to make it work? Thanks. Hi, I am calling the sms gateway to send sms, Quote $sms_msg = "hi this is mubarak"; $url = $urlAccount_home."?username=".$userAccount."&password=".$passAccount."&number=".$O_Mobile."&sender=".$userSenderSMS."&msg=".$sms_msg; if (!($fp =fopen($url,"r"))) echo "<br><center>خطا في الاتصال </center><br>"; $result =fread($fp,10); fclose($fp); when i am sending like this am sending only the message "Hi" I am not getting the whole message... What might be the problem in sending the sms gateway.. Please help me if you guys came to know, Thanks and Regards, Mubarak Hi all. What am I doing wrong here? I cannot read from the file with fopen, this is the code. <html> <body> <?php $file=fopen("welcome.txt","r"); ?> </body> </html> I get a blank page, although I have text written in that file. Whenever I set it to "w" it still shows nothing - when I check the file manually with notepad, I see that it's blanked - but I think thats meant to happen, after all "w" clears the file. Have I understood correctly? This still shows a blank page, but it says it can't find the file if it's not in the directory - how it should be. <html> <body> <?php $file=fopen("welcome2123.txt","r") or exit("Unable to open file!"); ?> </body> </html> tl;dr - Why doesn't fopen read anything from the txt file? Encodings match - everything is in UTF-8, although I doubt thats the problem... Help? So I am tryting to create a script to upload a CSV file into a MySql DB. It has like 10K records into SQL
My Code is copy below ...
I get the following errors.
Line 16 is the $handle
line 18 is the While Statement
Error:
Warning: fopen(): Filename cannot be empty in C:\local\htdocs\ADPStorage\DemandCSV.php on line 16 Warning: fopen()expects parameter 1 to be resource, boolean given in C:\local\htdocs\ADPStorage\DemandCSV.php on line 18 I use my script for another table and it worked like a charm. Less data and less colums do. Bad Code: (good Code sample below. this one) <?php $today = date("m.d.y.h.m.s"); echo $today; $BPTD_fy = '2014'; $BPTD_updatedate = $today; $conn = mysql_connect("Localhost","root","password") or die (mysql_error()); mysql_select_db("ds_storage",$conn); if(isset($_POST['submit'])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); while(($fileop = fgetcsv($handle, 100000, ",")) !==FALSE) { $BPTD_fy = $fileop[0]; $BPTD_Status = $fileop[1]; $BPTD_Classification = $fileop[2]; $BPTD_ProcureCat = $fileop[3]; $BPTD_Product = $fileop[4]; $BPTD_Project = $fileop[5]; $BPTD_DSCategory = $fileop[6]; $BPTD_Calculated = $fileop[7]; $BPTD_CapacityType = $fileop[8]; $BPTD_Amount = $fileop[9]; $BPTD_Jul = $fileop[10]; $BPTD_Aug = $fileop[11]; $BPTD_Sep = $fileop[12]; $BPTD_Oct = $fileop[13]; $BPTD_Nov = $fileop[14]; $BPTD_Dec = $fileop[15]; $BPTD_Jan = $fileop[16]; $BPTD_Feb = $fileop[17]; $BPTD_Mar = $fileop[18]; $BPTD_Apr = $fileop[19]; $BPTD_May = $fileop[20]; $BPTD_Jun = $fileop[21]; $BPTD_Location = $fileop[22]; $BPTD_Env = $fileop[23]; $BPTD_Requester = $fileop[24]; $BPTD_ServiceArea = $fileop[25]; $BPTD_ServiceGroup = $fileop[26]; $BPTD_DepHead = $fileop[27]; $BPTD_Recgroup = $fileop[28]; $BPTD_RecOwner = $fileop[29]; $BPTD_Entrydate = $fileop[30]; $BPTD_updatedate = $fileop[31]; $sql = mysql_query("INSERT INTO inv_bpt_demand (Status, Classification, ProcureCat, Product, Project, DSCategory, Calculated, CapacityType, Amount, Jul, Aug, Sep, Oct, Nov, Dec, Jan, Feb, Mar, Apr, May, Jun, Location, Env, Requester, ServiceArea, ServiceGroup, DepHead, Recgroup, RecOwner, Entrydate, updatedate) VALUES ('$BPTD_Status', '$BPTD_Classification', '$BPTD_ProcureCat', '$BPTD_Product', '$BPTD_Project', '$BPTD_DSCategory', '$BPTD_Calculated', '$BPTD_CapacityType', '$BPTD_Amount', '$BPTD_Jul', '$BPTD_Aug', '$BPTD_Sep', '$BPTD_Oct', '$BPTD_Nov', '$BPTD_Dec', '$BPTD_Jan', '$BPTD_Feb', '$BPTD_Mar', '$BPTD_Apr','$BPTD_May', '$BPTD_Jun','$BPTD_Location', '$BPTD_Env','$BPTD_Requester', '$BPTD_ServiceArea', '$BPTD_ServiceGroup','$BPTD_DepHead', '$BPTD_Recgroup','$BPTD_RecOwner','$BPTD_Entrydate','$BPTD_updatedate')"); if($sql) { echo 'Data Uploaded Successfully'; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>BPT Demand CSV</title> <link rel="stylesheet" type="text/css" href="file:///C|/local/htdocs/style/style.css" /> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> </head> <body> <div id="mainWrapper"> <form method="post" action="https://localhost/Storage/DemandCSV.php" enctype="multipart/form-data"> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--end mainWrapper--> </body> </html>Similar Working code (good) <?php $conn = mysql_connect("Localhost","root","password") or die (mysql_error()); mysql_select_db("ds_storage",$conn); if(isset($_POST['submit'])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); while(($fileop = fgetcsv($handle,1000,",")) !==FALSE) { $PC_Num = $fileop[0]; $PC_Name = $fileop[1]; $PC_BPTNUM = $fileop[2]; $PC_busclass = $fileop[3]; $PC_Note = $fileop[4]; $PC_Acro = $fileop[5]; $PC_type = $fileop[6]; ///echo $fileop[1]; $sql = mysql_query("INSERT INTO inv_names (PC_Num, PC_Name, PC_BPTNUM, PC_busclass, PC_Note, PC_Acro, PC_type) VALUES ('$PC_Num', '$PC_Name', '$PC_BPTNUM', '$PC_busclass', '$PC_Note', '$PC_Acro', '$PC_type')"); if($sql) { echo 'Data Uploaded Successfully'; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Upload CSV</title> <link rel="stylesheet" type="text/css" href="file:///C|/local/htdocs/style/style.css" /> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> </head> <body> <div id="mainWrapper"> <form method="post" action="https://localhost/Storage/Storage_CSV.php" enctype="multipart/form-data"> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--end mainWrapper--> </body> </html>Please help and thx in advance ~J Im installing and testing a web application, and im having a strange bug that annoyes me because it dint have any sense and also it dont affects really to the web functionality: if($_POST["eliminar"]==""){ $consulta='SELECT * FROM impressora where Activa=0'; $result=mysql_query($consulta,$conexion); echo"<table align=CENTER class='sample'>"; echo"<p align=center>LLISTA D'IMPRESSORES INACTIVES.</p>"; printf("<th>MODEL</th><th>MARCA </th>"); while($fila=mysql_fetch_array($result,MYSQL_ASSOC)){ echo"<tr>"; echo "<td>" . $fila["Model"] . "</td>"; echo "<td>" . $fila["Marca"] . "</td>"; echo"</td>"; if($_SESSION["admin"]!=0){ ?> <form method= "post" ACTION="impressores_inactives.php?idr=<?php echo($fila["Id_impressora"])?>"> <td colspan="2"><INPUT TYPE ="SUBMIT" NAME="eliminar" VALUE="Eliminar"></td> </form></td> <?php } echo "</tr>"; } echo"</table>"; }else{ echo 'eliminado'; echo $_POST["eliminar"]; //BORRAMOS DE LA BBDD LA IMPRESSORA $consulta="delete from impressora where Id_impressora='".$_GET["idr"] ."'"; $result=mysql_query($consulta); echo "<meta http-equiv=Refresh content=\" ; url=../Impressores/impressores_inactives.php\">"; } The problem is that php say that eliminar is undefinded, and if i test $_POST it says its empty. See that eliminar is the name of the submit post and its checked for a function that deletes a item. The problem is that script is actually working. I can delete the printer but with that error... and if i test the value of eliminar is always empty. Ask for any other explanation without a problem , the code is in spanish. Hey guys, First of all thanks in advance for all the help you can give me. I'm using a php shopping script called plaincart to create a webstore. All is fine but the admin part is not working properly. When i go to http://localhost/admin it redirects to http://localhost/admin/admin/login.php The index.php is in the root of the server and the admin files are in a folder called admin... What is wrong? Please tell me if you need any code. Thank you Ok, not sure what the problem is....hard to explain. I am trying to setup a login script but I get the normal: Warning: session_start() [function.session-start]: Cannot send session cache limiter error code. I have no white space above to cause problem. I have used this same code written by Jpmaster77 on a number of sites. What the strange thing is it also messed up a couple of my css text boxes. See the difference: http://www.monstersgonewild.ca/index.php - Problem http://www.monstersgonewild.ca/index1.php - Without session() I would post the code of the original page but it is 600+lines and growing. Anybody have any ideas? Hi, I get this error when I load the page, but after hitting ctrl f5 to refresh.. the error goes away and the page works perfectly. I have edited out my details. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: YES) Access denied for user 'user'@'localhost' (using password: YES) I know everything is set right.. I just don't get it.. I am going crazy of this. Ive cleared my browser cache.. even tried it on my android phone and it does the same thing. Thanks, Deceevn OK, this is a strange one I am hoping someone can help with. I have a file with a heap of functions which work fine. This file is included in my other files, and the function to display the content is called. For example I include the master file in guestbook.php, which calls showGuestbook(). Same with contact.php, it calles showContact(); etc. The file is outside the web root of the website calling it. So I went to add another function called downloadFile(). When I try to call the function, it gives me the "call to undefined function" error. I have tried renaming it to a few diff things, same error. So I thought there could be a brace error somewehere in the file. This is the strange bit.... When I put that function at the top of the file, the page seems to fail to parse. None of the functions are available... The function so far is simply: function downloadFile() { echo "Download File"; } Can anyone shed some light on this strange behaviour, especially the errors that occur just because I move the code higher up the file. Hi. I have to check if a session is started or not, and then, check for the rank of the user. For that i use two functions like is_administrator,etc. Well, but this isnt working. I cant get any clear way to know if a session have been already started or not. Code: [Select] function is_administrator() { session_start(); if (isset($_SESSION['usr']) and empty($_SESSION['usr'])) { $l = conect(); $user = $_SESSION['usr']; $cons = "SELECT * FROM `users` WHERE usr='" . $user . '\';'; $res = mysql_query ($cons,$l); $ob = mysql_fetch_array($res); if ($ob['tipo'] == 'A') { return true; } } return false; } What i want to do is to check if a sesion exist, if not, return false. If the sesion exist, check for the user rank and return true/false. Hi all! Firstly, I'd like to say a big hello to everyone Right, so I have a bit of a strange problem. I get no error, but my page stalls. So here's what I've got, a simple alphabet (A-Z) in capitals at the top of the page, created by: $alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); // then further down the page I have it looped as so: <?php foreach($alphabet as $link): ?> <a href="suppliers.php?filter=<?php echo $link; ?>"> <?php echo $link; ?> </a> | <?php endforeach; ?> So that's all cool. I then have this at the top of the page: $the_suppliers = (isset($_GET['filter']) && preg_match("/[^A-Z]*/",$_GET['filter'])) ? $suppliers -> get_all($_GET['filter']) : $suppliers -> get_all('all'); Now I have preg_match() in there as I was using ctype_alpha() to check for only alphabetical chars, and thought that might be my problem, but still get it with preg_match(); Anyway, my class method (get_all()) is: public function get_all($filter){ global $database; if($filter == 'all'){ $sql = "SELECT * FROM " . self::$table . " WHERE on_web = 1 ORDER BY RAND() LIMIT 10"; }else{ $sql = "SELECT * FROM " . self::$table . " WHERE on_web = 1 AND LEFT(name,1) = '" . $database -> sql_prep($filter) . "'"; } return self::find_by_sql($sql); } Now this works fine for b-z, but for some reason when the filter=A it just hangs..... I have ran the sql in phpmyamin and it returns the result straight away, so I know it's not the sql. Does anyone here know where I might be going wrong here? It's very odd and I've never come across this before, and not getting an error doesn't really help much. Any suggestions or pointers will be gratefuly received I have done a simple insert query on a comment system but it works once and when i go back and try add another record it just doesnt work at all. Code: [Select] <?php include ("class.database.connection.php"); // the database connection class include ("settings.config.php"); // hostname, password ect $name = $_POST["UserName"]; $email = $_POST["UserEmail"]; $comment = $_POST["UserComment"]; $sql="INSERT INTO comments (name, email, comment)VALUES('$name', '$email', '$comment')"; $result=mysql_query($sql); ?> if anyone can help me with this i would be a happy chappy! Hi!!! i created this code for my chatroom!! Code: [Select] <?php $usern=$_SESSION['etchat_'.$this->_prefix.'username']; $con1 = mysql_connect("localhost","manosir_main","***********"); if (!$con1) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manosir_manoshos_main", $con1); $query = "SELECT etchat_user_online_user_sex AS gender FROM db1_etchat_useronline WHERE etchat_user_online_user_name = '$usern'"; $result= mysql_query($query); $user = mysql_fetch_assoc($result); if($user['gender']=='m'){ ?> <span style=" font-size: 12px; font-family: tahoma; direction: rtl; font-weight: bold; color: #0000FF " > male</span> <?php } if($user['gender']=='f'){ ?> <span style= "font-size: 12px; font-family: tahoma; direction: rtl; font-weight: bold; color: #FF47D1" > female</span><?php } mysql_close($con1); ?> it gets the users`s username when he login from session and get his/her sex by mysql!!!!! the starnge part is this: when i login to page it doesnt work..but when i refresh the page it works in first opening the $usern is empty!! whats wrong!!!!!!! Hi Guys First sorry for my bad english. I have a strange problem with php upload form. When i click on submit button ( with uploaded pdf ) nothing happens. The pdf file is 17MB, but with smaller PDF the form works perfectly. Here is the form code: Code: [Select] <form id="pdf" name="pdf" method="post" action="" target="_self" enctype="multipart/form-data" > <p align ="center"> <input type="hidden" name="app_id" value="<?php print $app_id?>"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000000000"> <input type="file" name="file1" value="Upload PDF" device="files" accept="text/pdf" /> <input type="submit" name="sent" value="Send" /> </p> </form> at the beginning of the upload.php i have the following lines: Code: [Select] $sent = isset($_POST['sent']) ? $_POST['sent'] : false; When i debug $sent and $_POST i saw that they are empty : ( With smaller PDF works perfectly but now with 17MB pdf $sent is empty,the result from print_r($_POST) is Array() in php.ini i changed MAX UPLOAD to 20MB and then restarted my apache , but i think this doesn't matter. This problem is very strange : ) Thanks in advance:) Hi folks, I have an initial redirect page which directs to my main page, sending two reference variables as $_GET parameters: Code: [Select] header("Location: /ob/index.php?id=".$id."&ref=".$ref); The first thing this main page does is include a file which checks for those two values: Code: [Select] if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); session_start(); error_reporting(E_ALL); if (isset($_GET['id']) && isset($_GET['ref'])){ $_SESSION['id'] = $_GET['id']; $_SESSION['ref'] = $_GET['ref']; } if(!isset($_SESSION['id']) || $_SESSION['id']=="" || !isset($_SESSION['ref']) || $_SESSION['ref']==""){ echo ("This service requires a valid ID to run - your session may have expired, please refresh your browser to try again."); exit; } The main page loads fine - meaning that the $_SESSION variables have been set correctly. However, when the next page loads (including the same file), the $_GET values obviously aren't there but the $_SESSION variables should be intact. I am getting fails every time though in Opera and Safari (have checked in IE, FF and Chrome and all seems well). However, if I then refresh the browser - in both Opera and Safari - the next page loads fine and the $_SESSION variables are correctly set. Any ideas on this at all? Many thanks in advance, Rich Friends this is a very strange problem i,m facing i made a form by which you can enter comments to a topic i get the comment title and comment topic and date and the name and e mail of the one who insert a comment according to these variables $id1=$row2['id']; echo "$id1"; //Comment poster,s name $name =strip_tags(@$_POST['coname']); //Comment title $title =strip_tags(@$_POST['comtitle']); //ment poster,s email $mail =strip_tags(@$_POST['comemail']); //comment $com =strip_tags(@$_POST['limitedtextarea']); //comment,s date $d= date("Y-m-d"); notice that i,m printing the topic id and i used the variable $id1 to get it inorder to use it to show the comments for this topic later and it shows the right id for the shown topic then i used this code to insert these variable into the database if(isset($_POST['add']) and $_POST['add']=='comm'){ $insertcomm =mysql_query("INSERT INTO comments (com_name,com_title,com_mail,comment,com_date,tid) VALUES ('$name','$title','$mail','$com','$d','$id1')") or die("comments were not inserted"); if(isset($insertcomm)){ echo "comment inserted ";} } I am trying to do isset($_GET but I have a bizarre problem come up. I am using "id" as one of my fields but when I try to use it in the code it says it is not recognised. However I use this field quite widely. The code its coming up with is "Undefined variable: id" but I cant see why it has a problem with id. My code is: <?php if(isset($_GET['id'])){ $sql = mysql_query("SELECT * FROM productfeed WHERE id='$id' LIMIT 1"); } { while($row = mysql_fetch_array($sql)) $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>&#163; $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>"; } ?> Hi, I've done a search and cant find anything related to my problem. I have a newsfeed on my site and i want it to display with the latest news at the top. I have this code: Code: [Select] $get_news = "SELECT title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC"; This works fine on one of my sites but on another i've just hit a problem. It seems to sort only by the day, not the rest of the date. I made a news post today with date and time of "27 Mar 2011 at 12:54:02" but a post from "28 Jan 2011 at 19:59:52" is above it. Any ideas why this is happening? Thanks, Alex |