Search the Community
Showing results for tags 'file'.
-
i try this code to rename file when upload , the file name is rename in the folder or physical file .But in the database , it display 'array' not the name of file .How to save file name in the database ? $targetDirg= "folder/pda-semakan/gambar/"; if($_FILES['gambar']['size'] == 0 && $_FILES['gambar']['name'] == ""){ $fileNameg = $gambar; }else{ $fileNameg =explode(".",$_FILES['gambar']['name']); $newfilename= $stIC.'.'.end($fileNameg); $moveg =move_uploaded_file($_FILES["gambar"]["tmp_name"], $targetDirg.$newfilename); }
-
This is so strange. I have this bit of code that removes the .php extension from pages so that I can visit any page without typing .php at the end. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [L] The above code has always worked for me before. But for some reason today it stopped working on localhost and the live server(ipage hosting). Do you know why that might be?
-
Hey guys! I have a page that has multiple forms. I am trying to make a button that will save all the information from each textarea to a different .txt file. IE: textarea1 will save to textarea1.txt textarea2 will save to textarea2.txt textarea3 will save to textarea3.txt etc. I am able to save each individual form via individual submit buttons within each form, but I'd like to make a submit button outside of the other forms that saves all forms to their specific files. The code for one of the individual forms looks like this: <form method="post" action="?"> <h1>Physical Stats</h1> <textarea name="stats"><?php include ('resources/stats.txt'); ?></textarea> <br><input type="submit" name="update_stats" value="Update"/> </form> <?php if (isset($_POST['update_stats'])) { file_put_contents("resources/stats.txt", $_POST['stats']); } ?> Everything above works. And the code for the save all form looks like this: <form method="post" action="?"> <input type="submit" name="update_all" value="Update All"/> <br><br> </form> <?php if (isset($_POST['update_all'])) { file_put_contents("resources/stats.txt", $_POST['stats']); file_put_contents("resources/pro_exp.txt", $_POST['pro_exp']); file_put_contents("resources/pro_awards.txt", $_POST['pro_awards']); file_put_contents("resources/ama_exp.txt", $_POST['ama_exp']); file_put_contents("resources/ama_awards.txt", $_POST['ama_awards']); file_put_contents("resources/references.txt", $_POST['references']); } ?> This is the code I currently have and it's just not working. Right now the above code is actually clearing all of the text files. I'm afraid I'm a complete newb to writing scripts and I'm sure there is some rule about file_get_contents that I'm not aware of. Please help! Thanks!
-
Say I am uploading an image that gets resized. The resized image is a thumb. I have it's file path saved in the database and the image itself saved in a folder. Originally I was saving both to the database and folder. But now that I think about it, do I have to save the orginal image? Wouldn't I be saving up a lot of space if I only save the thumb image? What do you think?
-
I need to send a cURL request containing a file to upload as well as a JSON string. I can get a properly formatted request when sending the JSON, but the file is throwing it off. $curl_file_object = '@'.$tmp_name $postData= array( 'JSON'=> json_encode($jsonParams), $reference => $curl_file_object, ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $target); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data;")); curl_setopt($curl, CURLOPT_POST, true); // enable posting curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); // post data curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if any redirection after upload $response = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); debug($info); Am I the first one needing to send file binary data along with a json string to a server at the same time?
-
I didn't found any nice materials comparing the two ways of information unload to user. Neither have I a firm understanding of how high my learning curve should be in both cases, which of which to choose for better way. I'm a beginner asking for your professional word of advice. Help me to better formulate for search what I want, Please. I know keeping files and images in fs is better served by os/fs-drivers but i'm just learning and just trying to remember select * for "poking around". + i do hate images text analyzing it'll will be! Is it better to save files from MySQL fields via http headers, or it's even more better to perform the saving of the kept txt files (in one specific folder) and all the maintenance of tempfiles on server (archiving, indexing, cron/planning)? So: 1. Learning & get experience in file maintenance? vs 2. Finding out how to deal with protocols (download resuming) What I've found so far: header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length:'); There's a textfield full of appended edits of a specific user (for example list-ordering/or article appending). Headers should deliver it as a file, while skiping the file creation on a server. Or do I just learn how to do it with files and save just file link then accomplish the persistent file-links cleaning (because there would be lots of them)? One one side there is a certain straightforwardness in dealing with files, but then again I'd prefer the both ways while considering continuing to study MySQL-approach. I understand protocols/headers with PHP are no easy task that's why I'm hopefully leaving the last word for the professional.... Thanks in advance!
-
Hi guys I would like to get whole content of html file after I submitted a password. The problem is that the my code doesn't access the value for the file. I tried to create a session but i doesn't work. What other option do I have to get the content of the html file? session_start(); $selected_file = $_POST['radio1']; // get the filename of the file $fileinfo = pathinfo($selected_file); $filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename']; $password = 'code'; $lines = file("$filename.html"); $_SESSION['selectedfile'] = $selected_file; $_SESSION['file'] = $filename; $_SESSION['Scipt'] = ("$filename.html"); $_SESSION['Scipttext'] = $lines; $_SESSION['file2'] = $fileinfo; if (isset($_POST['submitradio'])) { echo '<div class="imageselected">'; echo '<img src="'.$_SESSION['selectedfile'].'" /></br>'.PHP_EOL; echo '</div>'; // check to see if a html file named the same also exists if(file_exists($_SESSION['Scipt'])) { echo "<form action='test_result.php' method='post'>"; echo '<div class="Password">'; echo 'Type in password to view full Script'; echo "<label><div class=\"Input\"><input type='password' name='passIT' value='passit'/></div>"; echo "<input type='submit' name='submitPasswordIT' value='Submit Password'/></div>"; echo '</div>'; echo "$filename.html shares the same name as $selected_file"; for($x = 1;$x<=15;$x++) { header( "Content-Type: file/html" ); $lines = ($_SESSION['Scipttext']); $new = strip_tags($lines); echo $lines[rand(0, count($lines)-1)]."<br>"; } // end of forloop } // end of check // start Sorrytext else { echo '<div class="NoScript">'; echo "Nothing available at the moment."; echo '</div>'; } // end Sorrytext } // End of submitradio if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ echo "You entered correct password"; readfile($_SESSION['Scipt']); } else{ echo "You entered wrong password"; } } echo '</form>'; I would be grateful for help.
-
I am in the process of creating a script where only certains video types can be uploaded but at the moment am stuck. Here is my code - <?php $title = isset($_POST['title']) ? $_POST['title'] : null; $desc = nl2br(isset($_POST['description'])) ? $_POST['description'] : null; $name = isset($_POST['fullname']) ? $_POST['fullname'] : null; $email = isset($_POST['email']) ? $_POST['email'] : null; $country = isset($_POST['country']) ? $_POST['country'] : null; $video = isset($_FILES['video']); $videoname = isset($_FILES['video']['name']); $videotmp = isset($_FILES['video']['tmp_name']); $videosize = isset($_FILES['video']['size']); $videotype = isset($_FILES['video']['type']); $videoacceptable = array( "video/mp4", "video/ogg", "video/quicktime", ); $videopath = "/videos/"; $videofile = $videopath . $video; if(isset($_POST['submit'])) { //ERROR MESSAGES / VALIDATION if(empty($title)) { $errors[] = "A title is required"; echo "<style type=\"text/css\"> #title { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif(strlen($title) > 80) { $errors[] = "Your title can only be 80 characters long"; echo "<style type=\"text/css\"> #title { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if(empty($desc)) { $errors[] = "A description is required"; echo "<style type=\"text/css\"> #description { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if(empty($name)) { $errors[] = "Please enter your full name"; echo "<style type=\"text/css\"> #fullname { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif(strlen($name) > 32) { $errors[] = "Your name can only be 32 characters long"; echo "<style type=\"text/css\"> #fullname { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if(empty($email)) { $errors[] = "Please enter your email address"; echo "<style type=\"text/css\"> #email { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif(strlen($email) > 50) { $errors[] = "Your email addess can only be 50 characters long"; echo "<style type=\"text/css\"> #email { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = "Please enter a valid email address"; echo "<style type=\"text/css\"> #email { background-color:#F5A9A9;border:1px solid #DF0101; } </style>"; } if($videosize = 0) { $errors[] = "You forgot to upload a video"; } elseif($videosize >= 20000000) { $errors[] = "Your video size is too large, 20mb max"; } elseif(!in_array($videotype, $videoacceptable)) { $errors[] = "The file type is not allowed, only allowed .mp4, .ogg and .mov"; } if(count($errors) === 0) { $connect = mysqli_connect("localhost","username","password"); if(!$connect) { header("Location:"); // ADD ERROR LINK } $dbselect = mysqli_select_db("database"); if(!$dbselect) { header("Location:"); // ADD ERROR LINK } $query = mysqli_query("INSERT INTO cover_videos(title, desc, name, email, country, videotmp, videotype, videosize, videopath) VALUES('$title','$desc','$name','$email','$country','$videotmp','$videotype','$videosize','$videopath')"); move_uploaded_file($videotmp, $videofile); //SEND AN EMAIL TO THE USER $to = $email; $subject = "Thank's for your upload"; $message = ' <html> <head><title>We have received your video</title></head> <body> <h3>Good News!</h3> <p>We have recieved your video and is awaiting approval.</p> </body> </html> '; $headers = 'FROM: no-replyk' . "\r\n"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); header("Location:"); //SUCCESSFUL UPLOAD PAGE } } ?> So whats happening is when i go to upload a file, im uploading a .mov file but the error message that pops up is "The file type is not allowed, only allowed .mp4, .ogg and .mov" but the .mov mime is in the videoacceptable array so im a bit stuck at the moment, any know whats the problem?
-
Hi Community! :-) (Sorry for my average english) I recently started coding in php, till now, i allready have advanced skills in programming with C# and thus, had no problems writing my own script. Still, my script does not really work, i'm trying to check if a file contains a md5(string), but the script never finds the string. This is the script: (please don't mind any security issues, this is just a test. But if you have any tips and tricks to improve the security, i'd be glad to receive them) <?php $webname = $_POST["webname"]; $webcode = $_POST["webcode"]; $webpass = $_POST["webpass"]; if (file_exists("web/". $webname . ".html")) { $file = file_get_contents("web/". $webname . ".html", "r"); if (strpos(md5($webpass),$file) !== false) { $usergen = fopen("web/" . $webname . ".html", "w") or die("Unable to open file!"); fwrite($usergen, $webcode); fwrite($usergen, "<!--- ". md5($webpass) . "--->"); fclose($usergen); echo "Generated! You can view your site under /web/" . $webname . ".html"; } else { echo "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered."; } } else { $usergen = fopen("web/" . $webname . ".html", "w") or die("Unable to open file!"); fwrite($usergen, $webcode); fwrite($usergen, "<br><!--- ". md5($webpass) . " --->"); fclose($usergen); echo "Generated! You can view your site under /web/" . $webname . ".html"; } echo "<FORM><INPUT Type=\"button\" VALUE=\"Back\" onClick=\"history.go(-1);return true;\"></FORM>"; ?> What it does it pretty simple, you enter some html-code that'll be stored in the "webcode" variable, a password, let's say "apple" in "webpass" and the filename is stored in "webname". On first creation, a html-file is created with the <!--- md5(apple) ---> at it's end, the HTML Tags are needed to hide the string from any visitors. If someone wants to edit the File created before, he also enters "apple". Then the string will be looked up as md5(apple) in the file. If the strings match, it's true and the changes should be saved. Whatever i do, though, i'm allways ending up here if i try to edit an existing file: "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered."; As i said, i'm a newbie, i'd appreciate any tips and help. Thank you in advance!
-
I have a .txt document named bannedIPS.txt that has this in it: 12.326.25.3 192.168.1.1 207.236.2.32 10.218.24.5 and then my php script has this //Gets user's IP $ipaddress = $_SERVER['REMOTE_ADDR']; //List of IPs to block $fh = fopen('UserIP/bannedIPS.txt','a+'); $ipBlockList = array(); $countWhileLoop = 0; while($line = fgets($fh)) { $ipBlockList[$countWhileLoop] = $line; $countWhileLoop++; } fclose($fh); //Determine if user IP is on the list for($i=0; $i<=$countWhileLoop-1; $i++) { //Debug for seeing what $ipBlockList[$i] is echo $ipBlockList[$i]."<br/>"; if($ipaddress==$ipBlockList[$i]) { echo "banned"; exit; } } My IP address is 207.236.2.32 so it should display: 12.326.25.3 192.168.1.1 207.236.2.32 banned but it displays: 12.326.25.3 192.168.1.1 207.236.2.32 10.218.24.5 so, the if statement isn't getting triggered. Why is that? I'v tried: if($ipaddress=="207.236.2.32") { echo "banned"; exit; } and then it works, but if it's the variable, it doesn't. PS. I just started learning PHP today from W3Schools and Google. Edit: Fixed typo
-
I have the following code $fp = fopen('/output/report_sort.txt', 'w'); if(!$fp) die('Could not create / open text file for writing.'); if(fwrite($fp, $txt1) === false) die('Could not write to text file.'); // Print the totals for each category $data = file('/output/report_sort.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); usort($data, fn($a, $b)=>substr($a,11,2)<=>substr($b,11,2)); // sort by code number $codes = []; foreach ($data as $d) { $p = strpos($d, ')'); $k = substr($d, 11, $p-10); if (!isset($codes[$k])) { $codes[$k] = 1; } else { $codes[$k]++; } } //echo (join("<br>", $data)); echo ("<font color='blue'><b><h3>Total clicks</h3></b></font>"); foreach ($codes as $code => $total) { printf("%s <font color='red'><b>Total clicks = %d<br></b></font>", $code, $total); } echo "<br />"; which from this data 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Spain Cartagena Murcia 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Spain Nerja Malaga 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Cedar Springs Michigan 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Spain Madrid Madrid 06/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 06/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 06/10/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 France 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 23 The Wedding Part 1 (La Boda) 30-7-2023.mp3 Ireland Dublin Leinster 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Cartagena Murcia outputs the totals for each category as follows 03 Resist the Curse (Resiste la Maldición) Total clicks = 2 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) Total clicks = 19 05 Day of Atonement 2023 (Día de la Expiación) Total clicks = 32 06 Feast of Tabernacles 2023 (Fiesta de los Tabernáculos) Total clicks = 4 07 The Eighth Day 2023 (El Octavo Día) Total clicks = 17 19 The Bread of Life (El Pan de la Vida) Total clicks = 20 20 Be With Me Where I Am (Está Conmigo Donde Estoy) Total clicks = 4 20 The Legacy of Jesus (El Legado de Jesús) Total clicks = 2 23 The Wedding Part 1 (La Boda) Total clicks = 1 what I would like is to combine lines which are duplicated to show 1 line as 1 click as follows 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Spain Cartagena Murcia 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Spain Nerja Malaga 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Cedar Springs Michigan 05/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Spain Madrid Madrid 06/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 06/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 06/10/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 France 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 United States Edmore Michigan 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 08/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster 09/10/2023 07 The Eighth Day 2023 (El Octavo Día) 1-10-2023.mp3 Ireland Dublin Leinster To be shown in the totals as 03 Resist the Curse (Resiste la Maldición) Total clicks = 1 07 The Eighth Day 2023 (El Octavo Día) Total clicks = 1 the same for all the other categories
-
The code works but it puts the files into /uploadir/. The users directories go by their email addresses ($email). Using the error reporting it tells me: ! ) Notice: Undefined variable: email in /var/www/html/Lab5/uploadfile.php on line 10 Call Stack # Time Memory Function Location 1 0.0010 129288 {main}( ) ../uploadfile.php:0 Any help is much appreciated!! <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors','1'); session_start(); if ($_COOKIE["auth"] == "1") { $file_dir = "/var/www/html/uploaddir/$email"; foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array["tmp_name"]."<br/>\n"; echo "name: ".$file_array["name"]."<br/>\n"; echo "type: ".$file_array["type"]."<br/>\n"; echo "size: ".$file_array["size"]."<br/>\n"; if (is_uploaded_file($file_array["tmp_name"])) { move_uploaded_file($file_array["tmp_name"], "$file_dir/".$file_array["name"]) or die ("Couldn't copy"); echo "File was moved!<br/>"; } } } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?>
- 6 replies
-
- file upload
- file
-
(and 3 more)
Tagged with: