PHP - Check For Files
Hi,
Here's my problem: The first 5 or 10 tries it should say "file not found". After the 10th try it should automatically say "file found". BUT it should also time out after like 50 tries and it hasn't found the file. But i don't know how to do this.. I currently have this code: Code: [Select] <?php function respond_xml($status, $message) { $out = new XMLWriter(); $out->openURI("php://output"); $out->setIndent(true); $out->startDocument("1.0", "ISO-8859-1"); $out->startElement("statuscheck"); $out->writeElement("status", $status); $out->writeElement("message", $message); $out->endElement(); $out->endDocument(); $out->flush(); } function main() { header("Content-type: text/xml"); if (!isset($_GET["file"])) respond_xml("ERROR", "File parameter missing"); else if (file_exists($_GET["file"])) respond_xml("OK", "File exists"); else respond_xml("NOT OK", "File does not exist"); } main(); ?> This code works and gives a correct XML response when you type in for example "http://localhost:8080/php/script.php?file=test" it's says: Code: [Select] <statuscheck> <status>NOT OK</status> <message>File does not exist</message> </statuscheck> Now, I need it to be able to check it every 5 seconds so i've use this code Code: [Select] header("Refresh: 5; URL=http://localhost:8080/php/script.php?file=test"); Similar TutorialsHi, I currently have this code: Code: [Select] <?php function respond_xml($status, $message) { $out = new XMLWriter(); $out->openURI("php://output"); $out->setIndent(true); $out->startDocument("1.0", "ISO-8859-1"); $out->startElement("statuscheck"); $out->writeElement("status", $status); $out->writeElement("message", $message); $out->endElement(); $out->endDocument(); $out->flush(); } function main() { header("Content-type: text/xml"); if (!isset($_GET["file"])) respond_xml("ERROR", "File parameter missing"); else if (file_exists($_GET["file"])) return respond_xml("OK", "File exists"); else return respond_xml("NOT OK", "File does not exist"); } main(); ?> This code works and gives a correct XML response when you type in for example "http://localhost:8080/php/script.php?file=test" it's says: Code: [Select] <statuscheck> <status>NOT OK</status> <message>File does not exist</message> </statuscheck> Now, I need it to be able to check it every 5 seconds so i've use this code Code: [Select] header("Refresh: 5; URL=http://localhost:8080/php/script.php?file=test"); Here's my problem: The first 5 or 10 tries it should say "file not found". After the 10th try it should automatically say "file found". BUT it should also time out after like 50 tries and it hasn't found the file. But i don't know how to do this.. Hello, Its my first day coding so please forgive me for some of the silly errors I might make.
I am writing a small upload script and I want to have some sort of orginazation by uploading images to a direcotry based on the day. The following is my code but it will fail to save the file Warning: file_put_contents(images/14-09-26/5425905a18bba.png): failed to open stream: No such file or directory This is becuase the directory with the data part is not created how should I go about first checking that this directory is there and then creating it ? <?php ini_set('display_errors',1); error_reporting(E_ALL); $today = date('y-m-j'); define('UPLOAD_DIR', 'images/' .$today. '/'); $img = $_POST['data']; $img = str_replace('data:image/png;base64,', '', $img); $img = str_replace(' ', '+', $img); $data = base64_decode($img); $file = UPLOAD_DIR . uniqid() . '.png'; $success = file_put_contents($file, $data); print $success ? $file : 'Unable to save the file.'; ?> Hello I have a simple question about file handling... Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs, and put the content of their file into an array? Like this: array: [SomePath/test.php] = "All In this php file is being read by a new smart function!"; [SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";and so on, until no further files exists in that rootdir. All my attempts went totally crazy and none of them works... therefore i need to ask you for help. Do you have any ideas how to do this? If so, how can I be able to do it? Thanks in Advance, pros So far I have managed to create an upload process which uploads a picture, updates the database on file location and then tries to upload the db a 2nd time to update the Thumbnails file location (i tried updating the thumbnails location in one go and for some reason this causes failure) But the main problem is that it doesn't upload some files Here is my upload.php <?php include 'dbconnect.php'; $statusMsg = ''; $Title = $conn -> real_escape_string($_POST['Title']) ; $BodyText = $conn -> real_escape_string($_POST['ThreadBody']) ; // File upload path $targetDir = "upload/"; $fileName = basename($_FILES["file"]["name"]); $targetFilePath = $targetDir . $fileName; $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION); $Thumbnail = "upload/Thumbnails/'$fileName'"; if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){ // Allow certain file formats $allowTypes = array('jpg','png','jpeg','gif','pdf', "webm", "mp4"); if(in_array($fileType, $allowTypes)){ // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; $targetFilePathArg = escapeshellarg($targetFilePath); $output=null; $retval=null; //exec("convert $targetFilePathArg -resize 300x200 ./upload/Thumbnails/'$fileName'", $output, $retval); exec("convert $targetFilePathArg -resize 200x200 $Thumbnail", $output, $retval); echo "REturned with status $retval and output:\n" ; if ($retval == null) { echo "Retval is null\n" ; echo "Thumbnail equals $Thumbnail\n" ; } }else{ $statusMsg = "File upload failed, please try again."; } }else{ $statusMsg = "Sorry, there was an error uploading your file."; } }else{ $statusMsg = 'Sorry, only JPG, JPEG, PNG, GIF, mp4, webm & PDF files are allowed to upload.'; } }else{ $statusMsg = 'Please select a file to upload.'; } //Update SQL db by setting the thumbnail column to equal $Thumbnail $update = $conn->query("update Threads set thumbnail = '$Thumbnail' where filename = '$fileName'"); if($update){ $statusMsg = "Updated the thumbnail to sql correctly."; echo $statusMsg ; } else { echo "\n Failed to update Thumbnail. Thumbnail equals $Thumbnail" ; } // Display status message echo $statusMsg; ?> And this does work on most files however it is not working on a 9.9mb png fileĀ which is named "test.png" I tested on another 3.3 mb gif file and that failed too? For some reason it returns the following Updated the thumbnail to sql correctly.Updated the thumbnail to sql correctly. Whereas on the files it works on it returns REturned with status 0 and output: Retval is null Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif' Failed to update Thumbnail. Thumbnail equals upload/Thumbnails/'rainbow-trh-stache.gif'The file rainbow-trh-stache.gif has been uploaded successfully. Any idea on why this is? I am using WPSQT plugin in my blog site .I code some files in PHP also.how to add that files in plugin files.
Hey, Trying to learn to generate PDF files, something apparently WAAAAYYY more complex than I thought. Can someone please give me an explanation on '$optlist' from this function..... PDF_load_image ( resource $pdfdoc , string $imagetype , string $filename , string $optlist ) What is it? PHP.net doesn't have any info at all. Thanks, IceKat. BTW - Any (recent) tutorials or pages would be appreciated. Everything I find is out of date or doesn't work. lets say I own a file, and you own a file, both these files are the exact same file, the only difference is the filename. So lets say we both have The Gimp 2.6 but one is named TG2.6.exe and the other is named the_Gimp-2.6.exe. What would be the best way to count the files that are the same even if they have a different file name? Another example would be: I have a file called me.jpg and someone else has a file me.jpg but they are two completely different pictures. What would I do to tell that? first of all...its good to see the site back .
my question guys is i'm wondering is there a way of getting the column number when reading a .cvs file?
ie. a, b, c, d, aa, ab etc?
$row = 1; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { //echo $data[$c] . "<br />\n"; } } fclose($handle); }now $num counts the columns...but i want to convert that into a alphabetical column...is there a easy solution? thanks guys I have told that the php files I was working on contains BOM by default cause of the editor I m using. I have installed other editor that can create php files without BOM. So my question is what's the difference between 2 files, one with BOM and other without BOM ? Any problems I may face for long term usage ? Which one is better to use ? Hello -- Other than organizational clarity for the developer, is there a particular advantage (e.g., security, file access speed, etc.) for placing web files (php, css, html, etc.) in various folders and sub-folders vs placing all files in the root directory or in one particular folder? Thanks. I know how to count the files: <?php $dir = $_SERVER[DOCUMENT_ROOT]."/api/sigs/cache/".$i[id]."/"; $files = scandir($dir); $result = count($files); printf("$result Signatures Generated"); ?> But i'm trying to make it so it only counts the files that were modified recently (That Day). I have a section where users can upload documents into our software. The code itself is a couple years old and could perhaps use some updating, but it seems some of the files (at this time it only seems to be *.pdf) that have been uploaded are not able to be opened and the error "the file is damaged and could not be repaired" is being displayed as an "Adobe Reader" error in Internet Explorer 8. The largest concern is that it is an irreversible error and many of the documents users have uploaded are now corrupt. I can't seem to find any relevant information from Google (or Adobe) that does anything towards resolving the problem. Note: This does not happen on every .pdf, and I am not sure if there is a common bond between the failing documents (trying to find this now). At the moment I have been uploading files to my server using <input type='files'> and binary encrytion. I would like to have more controll over the files tmp_name. is there a way to assing it befor hand? I'm an intermediate php coder however I have a new situation. I need to do some remapping of categories from CSV files we get from our supplier for our php ecommerce store. We use mySQL back end. We are importing data from a Supplier and need to remap the category names for our online store. There are 16,000 entries in the CSV file. This is what I need to do. 1) grab the CSV from the suppliers (from their ftp location) 2) remap the suppliers category names on the acquired CSV to our stores category names. I can either create a new table with the category name relation ships (probably best?) or read my mapping CSV ? 3) save the new CSV to our server where our auto import program can grab it. Eventually, Id like a cron to run the new script but for now Ill do it manually during testing period. Thats it! but... as simple as it sounds, I dont know how to start this. Below is an example of what needs to be dont just to clarify. PHP Code: Our Category(A) | Their Category(B) | Product (C) | Product Cat (D) | New Product Cat (E) 1. dog/leash/long | Pet/walking | Item A | Pet/sleeping|bed ** This is what we need to get** 2. dog/leash|long | Pet/walking | Item B | Pet/walking 3. dog/leash|long | Pet/sleeping bed | Item C | Pet/walking Here is my pseudo code: Code: [Select] for each value in Column D (run the test on each value in Column D) for each value in B as i ( check each value in Column B) if B(i) = D1 then E1 =A(i) end for end for The new path in this example for Item A would be A3 and would be written to E1. I have 15,000 entries to do. Thank you for any help hey, can some one provide a code to help me copy a folder called contents with files in it to another folder called items cheers Hi! I would appreciate your help... How can i include files with get and post data in order to avoid sql injections? The including data has utf8 encoding... Any suggestions??? Thanks in advanced!!! I've searched around the internet and can't find a good method to do this. To start, I have a database with a field called 'fpath' that stores the filepath (root-relative) to uploaded PDF's. In this case, they're scanned personnel files. What I'd like to do is be able to download relevant PDF's based on a generated report... such as all PDF's of a certain category or all PDF's for a certain user. If there's a specific PEAR package or other script out there that you know works well, I can research it on my own.. but each search result is bringing up a different method to do it, which makes me nervous. Thanks! Can you include a file and append info to be grabbed by using GET? For example, can you have an include file like this... Code: [Select] include('file.php?id=1'); And then in the file "file.php" I would use $_GET['id'] to do other things in the code. I tried it and it's not working. I'm getting this error... "Warning: include(file.php?id=1) [function.include]: failed to open stream: No such file or directory in..." Just want to find out if this should be doable before I continue testing why it's not working for me. If it should work, should I be using something other than include maybe? (like require or require_once?) Good day: I have a simple uploader form to upload video files. FLV and mpg files will upload without problems. But mp4, m4v, ogg and webm files will not upload. I get this error: Warning: copy() [function.copy]: Unable to access in /mounted-storage/home7/sub007/sc30390-PTUD/**********.com/admin123/insertvideo.php on line 32 Error Video not loaded. I have read about adding the files in config/mimes.php but I do not see that folder or files in my hosting service (which is servage). Any help will be appreciated. Thanks. |