PHP - Moved: Php Rename() Problems
This topic has been moved to HTML Help.
http://www.phpfreaks.com/forums/index.php?topic=354370.0 Similar TutorialsThis topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=327935.0 i have the following code: $filename = $this->getMsisdn().".png"; if (!file_exists(sfConfig::get('sf_upload_dir') . '/rainbowcode/images/profilepics/'.$filename)) { $filename = "Rainbow-code-1_blck.jpg"; //rename it to msisdn $source = imagecreatefromjpeg($filename); } i JUST want to rename "Rainbow-code-1_blck.jpg" to $this->getMsisdn().".jpg" ?? is this possible?? i want to have the SAME picture but it has a different name please help? thank you Ok, so i've managed to upload images, but now i'm trying to rename them to avoid replacement and i've done something like this: mysql_query( "INSERT INTO `softmarket`.`internet_securitate` (`internet_securitateID`, `nume_produs`, `descriere`, `versiune`,`poza`, `pret`, `disponibilitate_produs`) VALUES ('', '$_POST[titlu]', '$_POST[descriere]', '$_POST[versiune]', '$foto', '$_POST[pret]', '$_POST[disponibilitate]');"); Code: [Select] function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['foto']['name']) ; $ran2 = $foto."."; $target = "../images/"; $target = $target . $ran2.$ext; while (file_exists($target)) { $ran2 = 'copyof'.$ran2; $target = $target . $ran2.$ext; } if(move_uploaded_file($_FILES['foto']['tmp_name'], $target)) { echo "The file has been uploaded as ".$ran2.$ext; } else { echo "Sorry, there was a problem uploading your file."; } header('Location: succes.php'); but it renames them in a wierd way...what is wrong? Does anyone know how i can rename a PDF file name using PHP? What i have right now is a form where the user can upload a pdf file, however i want to be able to to rename the file and save it to the server. i coded this and it works previously but now its not working. its say: syntax error, unexpected $end. below in the code which rename the files <?php session_start(); if(!isset($_SESSION['myusername'])){ header("location:index.php"); } else { // get the new and prev file name $newn = $_POST[ 'filename' ]; $prevn = $_POST[ 'filepg' ]; // get user directory path $dirpath = "u/" . ($_SESSION['myusername']) . "/"; // new filename $newn = "$dirpath$newn"; //old filename $prevn = "$dirpath$prevn"; // rename to file rename("$prevn", "$newn"); echo "<center><br><br><h2>"; echo "The file $prevn has been renamed to $newn!</h2></center>"; header( 'refresh: 2; url=files.php' ); ?> <?php $zip = new ZipArchive; $res = $zip->open('test.zip'); if ($res === TRUE) { $zip->renameName('currentname.txt','newname.txt'); $zip->close(); } else { echo 'failed, code:' . $res; } ?> I can rename a text file name but I can't rename a folder name.Can you help me? Hi As i am a newbie, i finally been able to upload and resize an image, but i need to rename the files to random numbers, i have found a code but i dont know where i should have to embed it in my php can u please tell me where and how? this is my php if (isset($_POST['register']) && $_POST['register']) { $update = mysql_query("UPDATE agents SET credit= credit-1 WHERE username='$username'"); //image1 $nameone=$_FILES['myfileone']['name']; if ($nameone) { $dst_filename = resize_upload_image($_FILES['myfileone'], "images/"); if ($dst_filename !== false) { extract($dst_filename); $image1 = mysql_query ("UPDATE img SET image1='$img_filename', thumb1='$thumb_filename'"); } } function resize_image($srcfilename, $dstfilename, $new_width, $new_height) { $ext = strtoupper(pathinfo($srcfilename, PATHINFO_EXTENSION)); // JPEG image if(is_file($srcfilename) && ($ext == "JPG" OR $ext == "JPEG")) { // Get src dimensions list($width, $height) = getimagesize($srcfilename); // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($srcfilename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagejpeg($image_p, $dstfilename, 100); return TRUE; } // PNG image elseif(is_file($srcfilename) && $ext == "PNG") { // Get src dimensions list($width, $height) = getimagesize($srcfilename); // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefrompng($srcfilename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output imagepng($image_p, $dstfilename, 0); return TRUE; } return false; } function resize_upload_image($file, $path) { global $standard_width, $standard_height; global $thumb_width, $thumb_height; $img_name= $file['name']; $tmp_name= $file['tmp_name']; if ($img_name) { if (substr($path, strlen($path)-1) != "/") { $path .= "/"; } $original_img_name = $path."tmp-".$img_name; move_uploaded_file($tmp_name, $original_img_name); $img_location = $path.$img_name; $thumb_location = $path."thumb-".$img_name; if (resize_image($original_img_name, $img_location, $standard_width, $standard_height) === FALSE) { unlink($original_img_name); return false; } if (resize_image($original_img_name, $thumb_location, $thumb_width, $thumb_height) === FALSE) { unlink($original_img_name); return false; } unlink($original_img_name); return array("img_filename"=>$img_location, "thumb_filename"=>$thumb_location); } return false; } sp this is a time id which could be added $image_name=time().'.'.$extension; $filename = "img/". $image_name; $filename1 = "img/small_". $image_name; Hello Everyone.. I have a different sort of a question here.. I was looking if its possible to check the no. of files in a folder (wheather they be in any format) and if thts possible can i manupulate those files like renaming them.. like for instance i have 1000 files in a folder nd i wanna rename them all according to sum criteria.. like if there are 300 mp3 songs in a folder.. 1st i wanna do i check how many are in the folder exactly.. then i wanna rename each song cuz they have sum extra information of artist on the file name.. like hello darling (alize).mp3 i wanna rename them to hello darling.mp3.. nd i wanna do the same to all the files in that folder.. is der a way i can make this possible..? 1st check the total no. of files in a folder.. renaming each file according using a special symbol.. like if "(" symbol cums up it can explode the name.. nd we can have the correct name in title[0] nd the (alize).mp3 part in title[1]. we can just join title[0].mp3 to get the correct name out of each file..!! i hope u understand wat i need to doo!! wud be thankfull if anyone can help This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=332254.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=307298.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=359340.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321853.0 ok this grabs mp3 from 4shared but the download link appears as preview.mp3 how could i get it to be renamed as the original reach name like here_without_you.p3 or something else? Code: [Select] <?php $file = file_get_contents("http://www.4shared.com/audio/PmMMpPFs/here_without_you.htm"); $body = preg_replace("/.*file[^=]*=|\&volume.*/si", "", $file); preg_match("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\-\:\=\;\.\@\/]+)))/is",$body, $result); $download_url = $result[1]; print_r($download_url); ?> Hello I am new to programming, coding, php... and need some help. I have some code that uploads a file and does some basic checks but I also want it to rename the file possibly adding the time stamp. Heres what I have so far. cheers. $tbl_name="guestbook"; // Table name $email = $_REQUEST["email"]; $name = $_REQUEST["name"]; $comment = $_REQUEST["comment"]; $_FILES["file"]["name"]; $_FILES["file"]["type"]; $_FILES["file"]["size"]; $_FILES["file"]["tmp_name"]; $_FILES["file"]["error"]; $datetime = date("dmy"); $uploaddir = "upload/"; $filename = $_FILES["file"]["name"]; $pathinfo = pathinfo($_FILES['userfile1']['name']); mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); if($result){ echo "Successful added update to the Melody Bear Bulletin Board"; echo "<BR>"; echo "<a href='ViewBulletinBoard.php'>View Bulletin Board</a>"; } else { echo "ERROR"; } if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]. "<br>"; } } } else { echo "Invalid file"; } mysql_close(); ?> anyone can show example how i could remane the uploaded file name with users id along with some number? Code: [Select] //////////////////////////////////////uploader else if($action=="uploader") { echo "Upload your picture and copy the link <br/>after uploading to user it at gallery.<br/><br/>"; echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"index.php?action=uploaded&sid=$sid\">"; echo "Choose Pictu <br />"; echo "<input name=\"uploaded\" type=\"file\" /><br /><br />"; echo "<input type=\"submit\" value=\"Upload\" />"; echo "</form><br/>"; echo "<p align=\"center\">"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //////////////////////////////////////uploader else if($action=="uploaded") { $blacklist = array(".php", ".php.jpg", ".php.jpeg", ".php.gif", ".php.png", ".phtml", ".php3", ".php4"); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['uploaded']['name'])) { echo "<p align=\"center\">"; echo "Oops sorry we do not allow those files.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; exit; } } $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if (file_exists("../images/" . $_FILES["uploaded"]["name"])) { echo "<p align=\"center\">"; echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; }else{ //This is our size condition if ($uploaded_size > 25600){ echo "Your file is too large. We have a 25kb limit.<br/>"; $ok=0; } $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($_FILES['uploaded']['type'], $types)) { // file is okay continue } else { $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0){ echo "<p align=\"center\">"; Echo "Sorry your file was not uploaded.<br/> It may be the wrong filetype. <br/>We only allow JPG, GIF, and PNG filetypes.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //If everything is ok we try to upload it else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "<p align=\"center\">"; echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } else{ echo "<p align=\"center\">"; echo "Sorry, there was a problem uploading your file.<br/>"; echo "<br/><a href=\"http://index.php?action=main&sid=$sid\">Wml Home</a><br />"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } } } } [code] Hi everyone, im a newbie and have written this script, has taken me a day to get here. The form inserts data into the database, uploads a file and sends an email. All this works fine, what i am trying to do is rename the file to the id of the record and check to make sure it is a pdf. I would really appreciate any help. I've tried and tried and just cant get it to work. <?php switch ($_REQUEST['action']) { case 'recruit': foreach($_POST as $key=>$value){ $$key = $value; } if ((!$name) || (!$email) || (!$phone)) { $error_msg = 'Fields marked<span class="gold"> * </span>are required to submit the form'; }elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $error_msg = 'Invalid email address'; } echo "$error_msg","<br><br>"; if ($error_msg == ''){ $date=date("d/m/y", time()); $add="recruitment/".$_FILES[userfile][name]; $cleaned = stripit($add); $add2 = $cleaned; if(move_uploaded_file ($_FILES[userfile][tmp_name], $add2)); $Q = mysql_query("INSERT INTO recruitment (`name`,`phone`,`email`, `qual`,`exper`,`file`) VALUES ('$name','$phone','$email','$qual','$exper','$cleaned')"); foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $companyname = 'Mead Business college'; $companyemail = 'ross@emediastudios.com.au'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: ".$name." <".$email.">\r\n"; $headers .= "Reply-To: ".$name." <".$email.">\r\n"; $to = "".$companyname."<".$companyemail.">"; $subject = "Mead Business College Recruitment Form Submission"; $message = '<style type="text/css>"; <!-- .style { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; } --> </style> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="style"> <b>Details:</b><br /><br /> <b>Name:</b> '.$name.'<br /> <b>Email:</b> '.$email.'<br /> <b>Mobile No:</b> '.$phone.'<br /> <b>Qualifications:</b><br> '.$qual.'<br /> <b>Experience:</b><br /><br />'.$exper.'<br /><br /> <b>Uploaded resume:</b> http://www.mydomain.com.au/'.$cleaned.' </td> </tr> </table>'; mail($to, $subject, $message, $headers); echo '<table width="99%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="mybody">Hi '.$name.',<p />Thank you for your enquiry. An MBC Consultant will contact you shortly.<br /> <br /> </td> </tr> </table>'; }else{ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } echo ' <FORM ENCTYPE="multipart/form-data" id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=recruit"> <table width="489" border="0" cellspacing="5" cellpadding="0" class="formsw"> <tr> <td width="227">Name:</td> <td width="358"><input type="text" name="name" id="name" value="'.$name.'" /></td> </tr> <tr> <td>Contact Mobile:</td> <td><input type="text" name="phone" id="phone" value="'.$phone.'" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" value="'.$email.'" /></td> </tr> <tr> <td>Relevent Qualifications:</td> <td><textarea name="qual" id="qual" cols="45" rows="5" value="'.$qual.'"></textarea></td> </tr> <tr> <td>Recent Experience:</td> <td><textarea name="exper" id="exper" cols="45" rows="5" value="'.$exper.'"></textarea></td> </tr> <tr> <td>Upload Resume:</td> <td><input type="file" name="userfile" id="userfile" /></td> </tr> <tr> <td><input type="submit" name="submit" id="submit" value="Submit" /></td> <td> </td> </tr> </table> </form>'; } break; } ?> i am trying to display all the image from a dir and let the use lick on a image that takes them to other page where they can rename that image. or let them rename the image from the first page. here is what i have. Code: [Select] <?php SESSION_START(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="author" content="vs" /> <meta name="robots" content="index, follow" /> <title></title> </head> <body> <div id="centerColumn"> <div id="header"> </div> <p><span class="small"></span><br /> </p><br> <form method="post" action="data2file.php"> <?php echo ' <table> <tr><td>'; $username = $_SESSION['user']; $url = $username."./"; $handle = opendir ($url); while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".." && $file != basename(__FILE__)) { //echo '<table border=1><tr><td>'; echo '<a href="edit.php" ><img border=1 src="'.$file.'"></a>'; echo '<br />'; echo "<input type=submit name=$file value=Edit>" ; print $file; echo '<br>'; echo "Enter new name: <input type='text' name='new-name' length='30'> <textarea type=text size='1' height='1'style='display:none' name='file-name' >". $file ."</textarea>"; echo '<hr>'; //echo '</td></tr></table>'; } } echo '</td>'; echo ' </table>'; ?> </body> </html> it works i loads all the images. and here is the data2file.php code Code: [Select] <?php SESSION_START(); echo $_POST['new-name']; echo '<br>'; echo $_POST['file-name']; echo '<br>'; echo "Successfully!"; ?> it's just display the name of the file and the new name i want to give it. But it only does the last image in the dir. How can i make the first code work so if the user clicks on the edit button it will pull only that image file name to the data2file.php and then from the data2file.php it will rename the file name. I need to rename several hundred mp3's in a directory. I've tried this php script...but it seems to have missed every file from 19 to 29 (119-129, 219-229, 319-329 etc). The original names are in no particular order or fashion in how they're named. What's my best choice to rename these files to song1.mp3, song2.mp3 song3.mp3 etc.? Code: [Select] <?php $i = 1; foreach (glob("/xmas/*.mp3") as $filename) { copy ("$filename", "/newpopaudio/xmas$i.mp3"); $i++; } ?> This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=351896.0 |