PHP - Move_uploaded_file Function Change The File Name
I used the move_uploaded_file function to upload files to my server ,but the function changes the Arabic names of files because most of my files are Arabic named
how can I fix that ?
Similar TutorialsI upload an image and put every information inside $_SESSION['tmp'] and $_SESSION['path'] then once user click on button then i use move_uploaded_file($_SESSION['tmp'],$_SESSION['path']) but file uploaded not appeared in my upload folder, and again i try to echo everything but all information still kept well in $_SESSION is there something missing here? thanks HI All, I have a form submission that uploads a photo as well as submitting other data. I would like to change the name of the photo to the id of the person record (created automatically on by the database) then a hyphen, then their first name and lastname. (i am flexible on this). This file name will also need to be submitted into the person record so the photo and the person can be linked. I am struggling with this one - but here is the code i have so far.
<?php include 'includes/dbconn.php'; $target_dir = "img/people/"; $target_file = $target_dir . basename($_FILES["personHeadshot"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); if ($_SERVER['REQUEST_METHOD']=='POST'){ $fn = $_POST['fname']; $ln = $_POST['lname']; $ad1 = $_POST['ad1']; $ad2 = $_POST['ad2']; $city = $_POST['city']; $post = $_POST['postcode']; $tel = $_POST['phone']; $email = $_POST['email']; $crole = $_POST['comRole']; $OFA = $_POST['OFA']; $playerType = $_POST['playerType']; $team = $_POST['primaryTeam']; $stmt = $conn->prepare(" INSERT IGNORE INTO person (fname, lname, committee_role_id, player_type_id, team_id, ad1, ad2, city, postcode, mobile, email, on_field_auth_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt -> bind_param(ssiiissssssi, $fn, $ln, $crole, $playerType, $team, $ad1, $ad2, $city, $post, $tel, $email, $OFA); $stmt -> execute(); // Check if image file is a actual image or fake image //photo upload $check = getimagesize($_FILES["personHeadshot"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } //photo upload header("location: ../admin-people-list.php"); } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["personHeadshot"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["personHeadshot"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["personHeadshot"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } }
move_uploaded_file($_POST['file']['tmp_name'], "upload/"); doesn't work and if i echo the tmp name it comes up with the first letter of the uploaded file. please help! I have been trying to upload videos using the move_uploaded_file function but have come up with a new error which is displayed below. Warning: move_uploaded_file(/home/~unn_s003539/public_html/Sold/uploadsPC45 close up .jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_s003539/public_html/Sold/vidupload.php on line 25 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpUWYU51' to '/home/~unn_s003539/public_html/Sold/uploadsPC45 close up .jpg' in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_s003539/public_html/Sold/vidupload.php on line 25 Error when uploading the video./var/www/vhosts/numyspace.co.uk/httpdocs I don't understand why this error is occuring as the file target I'm using is exactly the same as the one in the ftp file which I have just copied across. My code looks like this: session_start(); include("connection.php"); $target = "/home/~unn_s003539/public_html/Sold/uploads"; $target = $target . basename( $_FILES['video']['name']); $name=$_POST['name']; $email=$_POST['email']; $title=$_POST['title']; $description = $_POST['description']; $pic=($_FILES['video']['name']); $sql="INSERT INTO `videos` (name, date, email, title, description, video) VALUES ('$name','CURDATE()', '$email', '$title', '$description','$pic')" ; $result=mysql_query($sql); if(move_uploaded_file($_FILES['video']['tmp_name'], $target)) { echo "Successful upload of ". basename( $_FILES['video']['name']); } else{ echo "Error when uploading the video."; }. Any Help would be greatly appreciated. Im trying to use move_uploaded_file() to move an uploaded file from the temp directory to a different directory and when I run this function I get this error: Quote Warning: move_uploaded_file(/home/mikeh/public_html/uzErUpl0ds/jx8zmPQW.rtf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/fileupload.php on line 238 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/Applications/XAMPP/xamppfiles/temp/phprQRBDe' to '/home/mikeh/public_html/uzErUpl0ds/jx8zmPQW.rtf' in /Applications/XAMPP/xamppfiles/htdocs/fileupload.php on line 238 There was an error uploading the file, please try again! I have no idea why, below is my code: Code: [Select] <?php $target_path = $uploadLocation . basename( $_FILES['upfile']['name']); $ext = end(explode('.', $_FILES['upfile']['name'])); function generatePassword ($length = 8) { // start with a blank password $password = ""; // define possible characters - any character in this string can be // picked for use in the password, so if you want to put vowels back in // or add special characters such as exclamation marks, this is where // you should do it $possible = "_12346789abcdfghjkmnpqrtvwxyzABCDFGHJKLMNPQRTVWXYZ"; // we refer to the length of $possible a few times, so let's grab it now $maxlength = strlen($possible); // check for length overflow and truncate if necessary if ($length > $maxlength) { $length = $maxlength; } // set up a counter for how many characters are in the password so far $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, $maxlength-1), 1); // have we already used this character in $password? if (!strstr($password, $char)) { // no, so it's OK to add it onto the end of whatever we've already got... $password .= $char; // ... and increase the counter by one $i++; } } // done! return $password; } $filename = generatePassword(); $filename = $filename.".".$ext; $filelocation = "/home/mikeh/public_html/uzErUpl0ds/".$filename; $allowed = "doc docx rtf txt pdf xls"; $allow = explode (" ",$allowed); if (in_array($ext,$allow)){ if(move_uploaded_file($_FILES['upfile']['tmp_name'], $filelocation)) { //TODO: Insert date regex format and make the catagory selection auto// $uid = $_POST['catagory']; $name =$_POST['title']; $author = $_POST['author']; $cat = $_POST['code']; $dt1=date("Y-m-d"); $size = filesize($filelocation); die($filelocation); $query = "INSERT INTO newnotes (uid, name, catagory, location, author, date, filesize) VALUES ('$uid', '$name', '$cat', '$filename', '$author', '$dt1','size')"; //die ($query); $res = mysql_query($query) or die (mysql_error()); echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded! It will be reviewed and if possible you will be granted credits within the next 24 hours."; } else{ echo "There was an error uploading the file, please try again!"; } }else{ echo "You have tried to upload an file type that we do not allow. The current allowed types of files are, ".implode(',',$allow).". If you are trying to upload a note with a diffrent file extension please use <a href=\"contact.php\">this form</a> to let us know so we can fix our website to allow this type of file in the future."; } ?> For the life of me, I cannot get an uploaded file to move from the tmp folder to the uploads folder. I have made sure all permissions were set to allow for the transfer. $upfile points to the right folder and file. print_r($_FILES); yields the following: Array ( [userfile] => Array ( [name] => 02.jpg [type] => image/jpeg [tmp_name] => /tmp/phpClFyXP [error] => 0 [size] => 121200 ) ) Any help would be greatly appreciated. HTML: Code: [Select] <html> <head></head> <body> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value = "2000000000"> Upload this file: <input name ="userfile" type="file"> <input type="submit" value="Send File"> </form> </body> </html> PHP: <html> <head> <title>Uploading...</title> </head> <body> <h1>Uploading file...</h1> <?php if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } // Does the file have the right MIME type? // put the file where we'd like it $upfile = '/timporn/uploads/'.$_FILES['userfile']['name']; echo $upfile; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo '<br>Problem: Could not move file to destination directory'; exit; } } else { echo 'Problem: Possible file upload attack. Filename: '; echo $_FILES['userfile']['name']; exit; } echo 'File uploaded successfully<br><br>'; // reformat the file contents $fp = fopen($upfile, 'r'); $contents = fread ($fp, filesize ($upfile)); fclose ($fp); $contents = strip_tags($contents); $fp = fopen($upfile, 'w'); fwrite($fp, $contents); fclose($fp); // show what was uploaded echo 'Preview of uploaded file contents:<br><hr>'; echo $contents; echo '<br><hr>'; ?> </body> </html> Hi guys, I'm a newbie in php programming and i would like to ask you guys about my issue... am trying to do a script that deletes a file from server and then upload an image to the server... unfortunately it doesn't work... i was able to get the upload part but after putting in the unlink() it doesn't work... the file is deleted from the server however it upload doesn't... hope you guys can assist me with this... thanks in advance... if(file_exists($file_src)){ unlink($file_src); } if(!empty($_FILES['userfile']['name'])){ //file variables $file_name = $_FILES['userfile']['name']; $temp_name = $_FILES['userfile']['tmp_name']; $file_type = $_FILES['userfile']['type']; //get extension of the file $base = basename($file_name); $extension = substr($base, strlen($base)-4, strlen($base)); //only these file types will be allowed $allowed_extensions = array(".txt", "docx", ".doc"); //check that this file type is allowed if(!in_array($extension,$allowed_extensions)){ header('Location:modify.php?action=errorupload&id='.$row['index']); } else{ move_uploaded_file($_FILES['userfile']['tmp_name'], "../files/" . $_FILES['userfile']['name']); $sql2 = "UPDATE t_board SET `writer` = '".$this->writer."', `subject` = '".$this->subject."', `message` = '".$this->message."', `filename` = '".$this->files['name']."' WHERE `index` = '".$this->id."'"; $query2 = mysql_query($sql2); $sql3 = "SELECT * FROM t_board WHERE `index` = '".$this->id."'"; $query3 = mysql_query($sql3); $row2 = mysql_fetch_array($query3); header("Location: view.php?action=edited&writer=".$row2['index']); }//in_array Howdy! I have been working in this custom script to manage some people on a group.. It will be really complete, with profiles, related stats and also an simple email client. But recently I have been having an issue with the function move_uploaded_file() to upload a picture to the user's profile. Apparently it works for some files (which means the syntax and paths are correct), but for some others move_uploaded_file() returns FALSE and I just can't work it out. Here is the part of the script that treats the uploading: Code: [Select] $target_path = "/opt/lampp/htdocs/emp/deeper/profiles/avt/"; //>>PATH<< to avt folder if (!isAllowedAvatar($_FILES['picture']['name'])) { //Check for allowed filetypes print "<div class='notif error bloc'><strong>Error :</strong> Wrong filetype. Image must be PNG file...</a></div>"; die; } if (file_exists($target_path.$basename.".png")) { //Rename old image to prevent loss of it in case of Failure rename($target_path.$basename.".png",$target_path.$basename."_temp.png"); } $old_path = $target_path; $target_path = $target_path . $basename . ".png"; //Build new image path if(move_uploaded_file($_FILES['picture']['tmp_name'], $target_path)) { //Moves uploaded image print "File ". basename($_FILES['picture']['name'])." correctly uploaded"; unlink($old_path.$basename."_temp.png"); //Deletes temp file } else { print "There was an error uploading the file, please try again!"; rename($old_path.$basename."_temp.png",$old_path.$basename.".png"); //Reverts the temp file to the original } I think the comments are enough for understanding it. Also, it looks like move_uploaded_file() is returning FALSE if the file is from Linux and had ownership stuff.. Any tip is welcome! Thanks for reading! Hi all i have stumbled across an issue and really need some help i have got a function below which i am using in a wordpress plugin. here is the code. // Base function function isd_s3player() { // Plugin Url $s3url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); echo '<object type="application/x-shockwave-flash" data="'.$s3url.'dewplayer-playlist.swf" width="235" height="200" id="dewplayer" name="dewplayer"> <param name="wmode" value="transparent" /> <param name="wmode" value="transparent" /> <param name="movie" value="'.$s3url.'dewplayer-playlist.swf" /> <param name="flashvars" value="showtime=true&autoreplay=true&xml='.$s3url.'playlist.php&autostart=1" /> </object>'; } ok the problem i am having is i cant passed the database variable to the playlist.php which the dewplayer needs to call within the function. is their a way to somehow use or set the playlist.php in this function without having to call it seperatly??? Here is my playlist.php <?php $bucket = get_option("isd-bucket"); $folder = get_option("isd-folder"); //include the S3 class if (!class_exists('S3'))require_once('s3/S3.php'); //AWS access info if (!defined('awsAccessKey')) define('awsAccessKey', 'amazon key'); if (!defined('awsSecretKey')) define('awsSecretKey', 'amazon secret key'); //instantiate the class $s3 = new S3(awsAccessKey, awsSecretKey); // Get the contents of our bucket $bucket_contents = $s3->getBucket($bucket,$folder); header("Content-type: text/xml"); $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $xml_output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">\n'; $xml_output .= "<trackList>\n"; foreach ($bucket_contents as $file){ $fname = $file['name']; $furl = "http://$amazon_bucket.s3.amazonaws.com/".urlencode($fname); if(preg_match("/\.mp3$/i", $furl)) { if (isset($outputted[$furl])) { continue; } $xml_output .= "\t<track>\n"; $xml_output .= "\t\t<location>" . $furl . "</location>\n"; $xml_output .= "\t\t<creator>" . $fname . "</creator>\n"; $xml_output .= "\t\t<album>" . $fname . "</album>\n"; $xml_output .= "\t\t<title>" . basename($fname) . "</title>\n"; $xml_output .= "\t\t<annotation>I love this song</annotation>\n"; $xml_output .= "\t\t<duration>32000</duration>\n"; $xml_output .= "\t\t<image>covers/smetana.jpg</image>\n"; $xml_output .= "\t\t<info></info>\n"; $xml_output .= "\t\t<link>" . $furl . "</link>\n"; $xml_output .= "\t</track>\n"; $outputted[$furl] = true; } } $xml_output .= "</trackList>"; echo $xml_output; ?> ok so as you can see right at the top i am trying to grab two option from the database but it doesnt allow you to do it this way within wordpress. So i guess what i am asking is their a way to completely skip the playlist.php file and do everything within the function??? Any help?? Hi guy, Does any know how to add a variable value to the name of a function in a loop e.g. Code: [Select] $i=1; while($qryRowName = mysql_fetch_assoc($qryName)){ $i++; function test$i(){ ***** } Is this possible? Please any help will be very much aprreciated Thanks } Hi there I'm a newbie to all of this so please be gentle! I am starting up my own online business and I am feeling my way through PHP. I have been doing ok so far but I'm having problems with the "change your password" function. I change the password, I receive a reactivation email, but when I try to log in with the new password it hasnt changed. Code I'm using as follows: <?php // process.php include 'config.php'; if(isset($_POST['changepassword'])) { $current = trim($_POST['current']); $new = trim($_POST['new']); $confirm = trim($_POST['confirm']); $pw = md5($current); $query = mysql_query("SELECT * FROM Users WHERE Password = '$pw' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($query) > 0) { while($row = mysql_fetch_array($query)) { if ( $_POST['new'] == $_POST['confirm'] ) {}else{ echo '<script>alert("Your passwords were not the same, please enter the same password in each field.");</script>'; echo '<script>history.back(1);</script>'; exit; } $password = md5($new); $do = mysql_query("UPDATE Users SET Password = '$password' WHERE Password = '$pw' LIMIT 1") or die(mysql_error()); $dotwo = mysql_query("UPDATE Users SET Activated = 0 WHERE Password = '$password' LIMIT 1") or die(mysql_error()); $send = mail($row['Email'] , "Password changed" , "Your password has been changed to: ".trim($_POST['new'])."\n\nYou can change it again via the members only panel, but first you must re-activate your account:\nhttp://www.infinite-monkey.co.uk/activate.php?id=".$row['Actkey']."\n\nDo not reply to this email, it is automated. Thanks." , "From: auto@mailer.com"); if((($do)&&($dotwo)&&($send))) { echo '<script>alert("Password changed. You will now be logged out and you must re-activate your account, check your email, a confirmation email has been sent.");</script>'; echo '<script>location.replace("logout.php");</script>'; exit; } else { echo '<script>alert("There appears to have been an error in the script. 1 or 2 of 3 things may have happened:\n\n• Your password could have been reset/changed\n• Your account could have been deactivated, see the resend validation email page\n• Your email may not have been sent.\n\nYou will now be logged out, if you are not able to login, reset your password using the form, or resend the validation email to activate your account again.\n\nWe are sorry for the inconvenience.");</script>'; echo '<script>location.replace("logout.php");</script>'; exit; } } } else { echo '<script>alert("Incorrect password.");</script>'; echo '<script>history.back(1);</script>'; exit; Hi all , here is a question about a disabled button . If I have a button: Code: [Select] <input id='submit' type='submit' disabled='disabled' value='submit'> Is it possible to change the "disabled=true" through php function ? such as Code: [Select] function change_button(){ echo "<script language=\"javascript\">"; echo "document.getElementById('submit').disabled=true;"; echo "</script>"; } I tried it , not working...is this function possible or have I make any mistake ? Thanks for every reply . This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330989.0 I wrote a bunch of code just to realize that there's a huge security hole in my script. Here's a how I've built it: 1. first you enter the new email address into the input box and click submit 2. an email gets sent to you where you have to click on an activation link to confirm the change, and of course the email gets send to the inbox to make sure it's a valid email the activation link looks as follows: Code: [Select] http://localhost/changeemail_confirm.php?id=$dbuser_id&email=$user_email The dbuser_id gets taken from the session variable, and the user email is the new entered user email. 3. After clicking the link you get directed to an activation page, I thought about letting the user enter his password and letting it match with the password in the database as added security, so he can't just change the user_id in the link so that the email of another user gets changed. the query on the activation page looks like this: "UPDATE user SET email = '$user_email' WHERE nickname = '$dbuser_name' AND WHERE user_id = '$id'"; The $id is being taking from the activation link per GET, and the $dbuser_name is being taking from the session variable. And now this is the problem where I'm stuck, even though I've added a bunch of security, and even the necessary to enter a password there's still a major security hole, which is the user can easily change the email in the activation link to something else, something that is not a valid email. E.g. this Code: [Select] http://localhost/changeemail_confirm.php?id=35&email=mail@phpmail.local can become to this, when the user manually edits the url and pastes it into his browser: Code: [Select] http://localhost/changeemail_confirm.php?id=35&email=MAIL@ANYTHING.com How can I prevent this, is there any way I could tell the script the CONFIRMED and VALID email, with a more secure way? BTW this script works as it is, it's just that the user can manually change the email to something else what makes this script worthless for now. Hello All I currently have a function that takes in user input from form fields $email & $password. If all is well the function logs the user in, if not redirects back to the login form. What I require is two things. 1) Allow the user to login with either "email" or "username" (entered in the $email form field). 2) Allow the system to have a "master" password and if that is entered with a valid email or user from above then log that user in. Here is my current function, any help is greatly received. Regards function loginMember($email,$password,$returnURL){ if ($email != "" && $password != ""){ $result = mysql_query("SELECT mid,memberid,forename,surname FROM tbl001_member WHERE emailaddress='$email' AND password='".$password."' AND online=1"); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); $_SESSION["logged_user"] = $row[2]." ".$row[3]; $_SESSION["logged_id"] = $row[0]; $_SESSION["logged_memid"] = $row[1]; session_unregister('wrong_email'); if (isset($_SESSION["logged_user"])) { header('Location:'.$returnURL); exit; } } else { session_register('wrong_email'); $_SESSION['wrong_email'] = $email; return "* There is no registered account with typed email & password."; } } else { session_register('wrong_email'); $_SESSION['wrong_email'] = $email; return "* Please input email and password correctly."; } } Hi I need to change the name of a file being uploaded by a user. The reason i need this is because there is a strong possibility that duplicate filenames would be logged. This is the code i have currently: Code: [Select] $upload_path = 'cv/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); // Upload the file to your specified path. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)); This code works fine to upload the file in the current name. I assume i need to seperate the filename from the file extension, and i can then assign a new variable to the filename. Easier said than done though as Ive tried many combinations of things. Is there a simple way using this script? or will i need to start from scratch? Cheers hi, i have a configuration file with this content for example: test = "100"; teste2 = "300"; now need change the test from 100 to 300, i just want use something like this: function ( "test" , 300 ); how can i do that? thanks for help Hi all Would like to ask for help . Generally I would like to run a webpage which will display actual price + price movements of selected cryptocurrencies.
I´m recieving data from extrernal API. (JSON) This is how code looks like: <?php $json = file_get_contents('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_market_cap=true;include_24hr_vol=true;include_24hr_change=true'); $bitcoinPrice = json_decode($json); $json = file_get_contents('https://api.coingecko.com/api/v3/simple/price?ids=dash&vs_currencies=usd&include_market_cap=true;include_24hr_vol=true;include_24hr_change=true'); $dashPrice = json_decode($json); $json = file_get_contents('https://api.coingecko.com/api/v3/simple/price?ids=netchain&vs_currencies=usd&include_market_cap=true;include_24hr_vol=true;include_24hr_change=true'); $netchainPrice = json_decode($json); $json = file_get_contents('https://api.coingecko.com/api/v3/simple/price?ids=pivx&vs_currencies=usd&include_market_cap=true;include_24hr_vol=true;include_24hr_change=true'); $pivxPrice = json_decode($json); function formatter($amount) { // $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); return '$'.number_format($amount, 2);; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <title>Masternodes monitor</title> <!-- Font Awesome --> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Material Design Bootstrap --> <link href="css/mdb.min.css" rel="stylesheet"> <!-- Your custom styles (optional) --> <link href="css/style.css" rel="stylesheet"> <!-- MDBootstrap Datatables --> <link href="css/addons/datatables.min.css" rel="stylesheet"> </head> <body> <table id="dtBasicExample" class="table table-striped table-bordered table-sm" cellspacing="0" width="100%"> <thead> <tr> <th class="th-sm">Coin name </th> <th class="th-sm">ROI </th> <th class="th-sm">Daily income </th> <th class="th-sm">Price </th> <th class="th-sm">24 change </th> <th class="th-sm">Volume </th> <th class="th-sm">Marketcap </th> <th class="th-sm">Node price </th> <th class="th-sm">Coins for MN </th> <th class="th-sm">Nodes </th> </tr> </thead> <tbody> <tr> <td><img src="/img/btc.png" width="15" height="15" title="Bitcoin logo" alt="Bitcoin logo" /> Bitcoin (BTC) </td> <td>Unknown</td> <td>Unknown</td> <td><?=formatter($bitcoinPrice->bitcoin->usd) ?></td> <td><?=formatter($bitcoinPrice->bitcoin->usd_24h_change) ?></td> <td><?=formatter($bitcoinPrice->bitcoin->usd_24h_vol) ?></td> <td><?=formatter($bitcoinPrice->bitcoin->usd_market_cap) ?></td> <td>Unknown</td> <td>Unknown</td> <td>Unknown</td> </tr> <tr> <td><img src="/img/pivx.png" width="15" height="15" title="Pivx logo" alt="Pivx logo" /> Pivx (PIVX)</td> <td>Unknown</td> <td>Unknown</td> <td><?=formatter($pivxPrice->pivx->usd) ?></td> <td><?=formatter($pivxPrice->pivx->usd_24h_change) ?></td> <td><?=formatter($pivxPrice->pivx->usd_24h_vol) ?></td> <td><?=formatter($pivxPrice->pivx->usd_market_cap) ?></td> <td>Unknown</td> <td>10,000</td> <td>1,536</td> </tr> <tr> <td><img src="/img/dash.png" width="15" height="15" title="Dash logo" alt="Dash logo" /> Dash (DASH)</td> <td>7.5%</td> <td>14,40 $</td> <td><?=formatter($dashPrice->dash->usd) ?></td> <td><?=formatter($dashPrice->dash->usd_24h_change) ?></td> <td><?=formatter($dashPrice->dash->usd_24h_vol) ?></td> <td><?=formatter($dashPrice->dash->usd_market_cap) ?></td> <td>$69,696.22</td> <td>1000</td> <td>4001</td> </tr> <tr> <td><img src="/img/ntx.png" width="15" height="15" title="Netchain logo" alt="Netchain logo" /> Netchain (NTX) </td> <td>350%</td> <td>0,12 $</td> <td>$0.00004</td> <td><?=formatter($netchainPrice->netchain->usd_24h_change) ?></td> <td><?=formatter($netchainPrice->netchain->usd_24h_vol) ?></td> <td><?=formatter($netchainPrice->netchain->usd_market_cap) ?></td> <td>$7</td> <td>100.000</td> <td>55</td> </tr> </tbody> <tfoot> <tr> <th>Coin name </th> <th>ROI </th> <th>Daily income </th> <th>Price </th> <th>24 change </th> <th>Volume </th> <th>Marketcap </th> <th>Node price </th> <th>Coins for MN </th> <th>Nodes </th> </tr> </tfoot> </table> <!-- SCRIPTS --> <!-- JQuery --> <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script> <!-- Bootstrap tooltips --> <script type="text/javascript" src="js/popper.min.js"></script> <!-- Bootstrap core JavaScript --> <script type="text/javascript" src="js/bootstrap.min.js"></script> <!-- MDB core JavaScript --> <script type="text/javascript" src="js/mdb.min.js"></script> <!-- MDBootstrap Datatables --> <script type="text/javascript" src="js/addons/datatables.min.js"></script> <script> $(document).ready(function () { $('#dtBasicExample').DataTable(); $('.dataTables_length').addClass('bs-select'); setTimeout(function() { location.reload(); }, 900000); }); </script> </body> </html>
I need section usd_24h_change in percent %. I tryed : <td><($bitcoinPrice->dash->usd_24h_change) ? % ></td> <td><($dashPrice->dash->usd_24h_change) ? % ></td> <td><($netchainPrice->dash->usd_24h_change) ? % ></td> <td><($pivxPrice->dash->usd_24h_change) ? % ></td> But it doesn´t work… Please help Edited October 26, 2019 by NetchainOk so I have this script that I wrote and it works really good. I wanted to display the number of records in a table and since the db only changes once per day I thought I would put the couner on the back end. I have this script that changes the value of the text file every day. But I would love it if it outputted with commas.
Now it reads:
1234070
Want it to read:
1,234,070
Any thoughs?
#!/usr/bin/php -q <?php $username=""; // READONLY USER USED HERE AND AUTH'D ON LOCALHOST ONLY $password=""; $database=""; $dbhost=""; mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to connect to database please try again!"); $counthd=mysql_query("SELECT count(*) as total from HD"); $hdtotal=mysql_fetch_assoc($counthd); $dbcount = $hdtotal['total']; echo ""; $myFile = "dbcounter.txt"; $fh = fopen($myFile, 'w'); fwrite($fh, "$dbcount"); fclose($fh); ?> Edited by chadrt, 01 February 2015 - 07:26 PM. |