PHP - Folder/subfolder Creation
Hi,
I am wanting to check to see if a folder exists, if not create it. PHP on a windows machine so I would like to know how to handle the folder separators. I am wanting to use a path which includes the drive letter, such as... $foldername ="C:\folder1\images\$checkfolder" I was thinking about using something like this: if(!is_dir($foldername)) mkdir ("$foldername",777); What would be the best way of tackling this using windows paths? Similar Tutorialshi all, i have this music website and i have to upload every album under this folder "newsongs" ... in AlbumName folder i have normal quilty songs and HQ folder..under HQ folder i have High Quilty songs for each album. i have this coding which moves Album folder and normal quilty songs to other folder "songs" but i also want to move subfolder "HQ" and High Quilty songs with AlbumName folder for($i=0;$i<=$ct;$i++) { $alb=$alname[$i]; $cat=$catname[$i]; $albids=$albid[$i]; $fon=$folder_name[$i]; $tmp_name=$doc_root."newsongs/$fon"; $uploads_dir=$doc_root."songs/$cat/$fon"; if ($handle = opendir($tmp_name)) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { //echo "$file\n <br>"; if($file !=='..' and $file !=='.') { $song_path="songs/$cat/$fon/$file"; if(!is_dir("$tmp_name/$file") and (!is_dir("$uploads_dir/$file"))) { if(copy("$tmp_name/$file", "$uploads_dir/$file")) { $cp=1; $ext=substr($file,-4); if($ext=='.mp3') $insqry=mysql_query(" insert into tbl_songs set song_name='$file', album_id='$albids', artist_id='$artid', song_path='$song_path' "); unlink($tmp_name.'/'.$file); } else { echo "could not move songs "; } } } if($insqry) $msg="songs Added to the database"; else $msg="songs Not Added to the database"; } closedir($handle); thnx in advnce I was wanting to make my own version of TinyURL for my personal use. So far, the only way I can get it to work as trim as possible is using the format: http://www.mysite.com/?tag TinyURL can do http://tinyurl.com/tag instead. I know dropping the ? is a trifling thing, but I'd like to figure out how they did it. I could do it by just creating subfolders and dropping an index.php in there that does a redirect, but I wasn't sure if there was a more efficient way....? This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=357293.0 I got this script: But it give me error, file_get_contents cannot open stream. I need to add the FTP connection with user/pass paramaters. then look in set http url, to get the file contents(images) and transfer to ftp server location. Can Anyone take alook and tell me if I am going down the right path and how to get there. Please Code: [Select] function postToHost($host, $port, $path, $postdata = array(), $filedata = array()) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n"); // Ab dieser Stelle sammeln wir erstmal alle Daten in einem String // Sammeln der POST Daten foreach($postdata as $key => $val){ $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } // Sammeln der FILE Daten if($filedata) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n"; $data .= "Content-Type: ".$filedata['type']."\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $filedata['data']."\n"; $data .= "--$boundary--\n"; } // Senden aller Informationen fputs($fp, "Content-length: ".strlen($data)."\n\n"); fputs($fp, $data); // Auslesen der Antwort while(!feof($fp)) { $res .= fread($fp, 1); } fclose($fp); return $res; } $postdata = array('var1'=>'today', 'var2'=>'yesterday'); $filedata = array( 'type' => 'image/png', 'data' => file_get_contents('http://xxx/tdr-images/images/mapping/dynamic/deals/spot_map') ); echo '<pre>'.postToHost ("localhost", 80, "/test3.php", $postdata, $filedata).'</pre>'; I want to copy everything in templates/blue to the folder code/ However: shell_exec("cp -r 'templates/blue' 'code'"); Creates a folder called blue inside code. I tried cp -r 'templates/blue/*' 'code', but that didn't do anything. Any ideas? Whats is the best way to create a forum using php? Should I use any frameworks? If not is there any guide/tutorial/book that descibe this procedure? Thank you. i have mysql community server 5.5 workbench 5.2 php 5.3.8 apache http server 2.2 summary: can i write the same code using less variables for the file name and content? okay so i managed to write a code that creates a filename, and each new filename is 1 higher. colony1 colony2 colony3. it also uses the same mysql query created variable to write idcol as 1 higher in the new file than in the previous written file. however to write the code i had to use a buttload of variables. here is the code, the resultant filename and the resultant content of the created file. is there a way to write such a code with less than 15 variables? the problem seems to be that when writing text to a file, i cannot insert certain characters outside of a variable into the final variable which is put in the $string variable input into the fwrite() function. File Name: Colony$.php where $=the last entry in the idcol column in table coltest. File Code: Code: [Select] <?php $idcol = $; include('Colony0.php'); ?> </body> </html> where $=the last entry in the idcol column in table coltest. Code: Code: [Select] <?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'aosdb'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query = "SELECT idcol FROM coltest ORDER BY idcol DESC LIMIT 1"; $result = mysql_query($query); $id = mysql_result($result, 0); $vcol = "Colony"; $vcolp = ".php"; $File = "$vcol$id$vcolp"; $FileHandle = fopen($File, 'w') or die("can't open file"); fclose($FileHandle); $File = "$vcol$id$vcolp"; $myFile = $File; $fh = fopen($myFile, 'w') or die("can't open file"); $idw = "$"; $icol= "idcol"; $ique = "?"; $iphp = "Colony0.php"; $ief = "<"; $ieb = ">"; $irese = "= "; $iresn = ";"; $iii= "include('$iphp');"; $ihtml ="</body> </html>"; $hph = "php"; $string = "$ief$ique$hph $idw$icol $irese$id$iresn $iii $ique$ieb $ihtml"; fwrite($fh, $string); fclose($fh); ?> I am attempting to create an image and I have run into a snag. I want to add both text and another image to the image I am making. Here is the code so far minus unnecessary parts: header ("Content-type: image/png"); $name = $fetch_user['username']; $rank = $fetch_rank['rank_title']; $img_url = 'path''. $fetch_rank['rank_image']; $im = @imagecreatefrompng("$img_url") or die("Cannot Initialize new GD image stream"); // try changing this as well $font = 4; $width = imagefontwidth($font) * strlen($string) ; $height = imagefontheight($font) ; $im = imagecreatefrompng("image.png"); $x = imagesx($im) - $width ; $y = imagesy($im) - $height; $backgroundColor = imagecolorallocate ($im, 255, 255, 255); $textColor = imagecolorallocate ($im, 255, 255, 255); //imagestring ($im, $font, $x, $y, $string, $textColor); imagestring ($im, $font, 100, 10, $name, $textColor); imagestring ($im, $font, 100, 22, $rank, $textColor); imagepng($im); Everything works UNTIL I added in this part: $im = @imagecreatefrompng("$img_url") or die("Cannot Initialize new GD image stream"); Any idea what I am doing wrong? All that comes up is "Cannot Initialize new GD image stream"; and I know the URL's work. With the following code i can create an xml file. Code: [Select] <?php $myXML = new SimpleXMLElement("<myroot></myroot>"); $title= $myXML->addChild('title'); $title->addAttribute('number','12'); $titleName= $title->addChild('titleName', 'title1'); $titleLink= $title->addChild('titleLink', 'link1'); Header('Content-type: text/xml'); echo $myXML->asXML(); ?> But when i check the validity of xml file http://www.validome.org/xml/validate/ This error occurs: Can not find declaration of element 'myroot'. I suppose that the problem is missing of !DOCTYPE and !ELEMENT lines. How can i create valid XML documents with PHP automatically?? Is it possible to make it without writing doctype and element types for the whole element types of xml by hand $title, $titleName and $titleLink Thank you I am trying to create a basic image with GD library, but my browser says that the image cannot be displayed because it contains errors... I have no idea why. Here's my code: Code: [Select] switch($_GET['case']){ case "progressbar": header('Content-Type: image/jpeg'); $barWidth = 6; $barHeight = 14; $barPadding = 2; $imageWidth = ($barWidth * 10) + (10 * $barPadding); $imageHeight = ($barHeight + ($barPadding * 2)); $img = @imagecreate($imageWidth, $imageHeight); $imgBorder = imagecolorallocate($img, 0, 0, 0); //imagefilledrectangle($img, 1, $imageHeight -1, $imageWidth - 1, $imageHeight - 1, $imgBorder); $output = "Hello, world!"; imagestring($img, 1, 4, 4, $output, $imgBorder); imagejpeg($img); imagedestroy($img); break; } I have a file called image.php that i use to create images and I use the URL image.php?case=progressbar. I am not sure what to look for to even get started. If some one could help point me in the right direction that would be appreciated.
I created a customer system that tracks contracts and invoices ect. Where do I start if I would want a customer to be able to go to the website, sign up, and their own version of the system would be created.
Do I just write a script that creates a new database with the correct credentials? Do all of the users access the same files but just have different database. Do I have to copy the directory of files to a specific folder for each customer?
I know there must be tons of websites that once you sign up for example a calendar app that keeps your data seperate from everyone else.
Any help is appreciated.
Thanks
Jack
Hey, guys, in the following code, why i cannot see my ~/test.txt file? It seem he is not doing what i want, to create a .txt file with 'is just a test'. I'm using Debian.
<?php $f = fopen("~/test.txt","w+"); fwrite($f,'is just a test'); fclose($f); ?>Thank you! Day
I'm using Codeigniter and inside the framework I create a file with PHP code If I try to point to it, the web-server doesn't deliver due to permission issues.
All this is done in a 'register function' where I create some fields in a SQL
If I put the user credentials into the database 'by hand' and likewise when I
I'm pretty sure this issue has been existed before and I'd appreciate any help.
Thanks for your help in forward. Gee Edited August 17, 2020 by bogusHi All I am trying to insert a feed on my site that automatically updates the football league etc like this one http://news.bbc.co.uk/sport1/hi/football/eng_div_1/table/default.stm is there a way to do this please? thanks This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=321416.0 I've been stuck on this for about a week so I was wondering if I can get some help from you guys! Basically I'm exporting an array of values to a CSV file, within that array are two other arrays containing data I need. What I need to work out is how I can create a CSV with headers for these values, then with the nested arrays also print their values into the same rows as the first array. Example: $List = array ( 'Product ID' => '10', 'Customer Address' => '123 Fake Street', array( array('Product Name'=>'Product1', 'Product Price'=>'10.00', 'Product Reference'=>'HGJEN'), array('Product Name'=>'Product2', 'Product Price'=>'5.00', 'Product Reference'=>'HGJTN'), array('Product Name'=>'Product3', 'Product Price'=>'10.00', 'Product Reference'=>'HGJNN'), ), array( array('Product Customisation Name'=>'Additional Info', 'Customisation Value'=>'Things are great.'), array('Product Customisation Name'=>'Image Upload', 'Customisation Value'=>'Logo.jpg'), ), 'Telephone Number'=>'999', ); To be exported to something looking like this: Product ID Customer Address Product Name Product Price Product Reference Product Cus Name Cus Value Telephone Number 10 123 Fake Street Product2 5.00 HGJTN Additional Info Things are great 999 10 123 Fake Street Product1 10.00 HGJEN Image Upload Logo.jpg 999 10 123 Fake Street Product3 10.00 HGJNN 999 If anyone could help me out in anyway I would be so appreciative, I'm sure this ones going to end up killing me! Hi all, Weird one: I am re-working a site for a client. Their old site currently grabs text from a DB and somehow automatically puts it into a <ul>. The only thing to signify a <li> is a linebreak. So if I entered: Item 1 Item 2 Item 3 into the database, they would come out looking like: Item1 Item 2 Item 3 on the site. Anyone know of a way to recreate this? An example of this in action is he http://www.postureperfection.com.au/Chairs/Amore_Chair/p/495/ (please remember - I am redesigning the site!) Thanks heaps! Hi So I have successfully set up a website and database where a user can create a listing and view listings on a listing details page. The viewing can only be done, however, only from either from either running a search query from the search form or from clicking one of the listings from the listing table. The listings are not being indexed from the search engines from the direct page, instead from the listing table which is about 3,000 listings, not very user friendly to land on this page and have to go through the table or use the table filter. Here's what I am trying to accomplish: A web page that has a dynamic presence / URL like a Wordpress page: http://www.mysite.com/listing_title/ The title of the page has the listing information in it: This page is about a $listing_title $listing_item listing number $listing_number that is online! Each individual Listing / page is indexed on the search engines and has a direct link to it I am familiar with PHP and have created this site but I am far from an expert! Please give me a code example or link to one because if you just say "do this to this and that" you will totally loose me. Thank you so much for any help. I was not sure on which board to put this thread, so please move it if there is a more appropriate board. I am wanting to create a website that displays images which I have put into a database. I would like the number of images on one page not to exceed 10, for example, and when the number of images in the database exceeds this number, a new page will be created. I would like it to function similar to Google Images where the number of pages is dictated by the number of images in the database. I cant figure out how to achieve this, so any pointers or thoughts would be great Thanks, Matlab Hi All,
I've been interested in writing a PHP pdo configuration file so that I can include connections in various files on my site. While I was looking up some possible solutions I stumbled across an interesting post on stack overflow http://stackoverflow...-pdo-connection
The first responder suggested the code below. However, I don't understand how to access the connection and make query calls. I'm confused by how it's possible to return a variable name as an object { return new $name( $this->connection ) }.
Also, If someone could explain what the author means by { $something = $factory->create('Something');}. Wouldn't the "Something" need to be a class? And how would that class get the db connection?
All the best,
Karma
$provider = function() { $instance = new PDO('mysql:......;charset=utf8', 'username', 'password'); $instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $instance->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $instance; }; class StructureFactory { protected $provider = null; protected $connection = null; public function __construct( callable $provider ) { $this->provider = $provider; } public function create( $name) { if ( $this->connection === null ) { $this->connection = call_user_func( $this->provider ); } return new $name( $this->connection ); } } $factory = new StructureFactory( $provider ); $something = $factory->create('Something'); $foobar = $factory->create('Foobar'); |