Jump to content

renno

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

renno's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a variable containing a string submitted from a form: [code]$string = ($_POST["string"]);[/code] I'm struggling to build some code that would replace any spaces in the string with the underscore character and then store back into a different variable $string2... Could anyone give me a point in the right direction? Cheers
  2. Thanks very much, will let you know how it goes...
  3. I have used php to create a directory on my remote webserver using: [code]mkdir("../$com_name1");[/code] However when I now try to create / add / write files (still using php) to this directory I get permission errors. This code works fine when I'm testing it on my own computer (localhost), but is failing when I try to execute it after uploading to the web... Can someone see where I'm going wrong? [code]$maxlines=500; //change this to set the maximum lines $lines=file("../temp.php"); //Get an array with the lines $numlines= (count($lines)>=50) ? ($maxlines-1) : (count($lines)-1); //number of lines to write $fp = fopen ("../{$_POST['company']}/index.php", 'w+'); // Convert from array to string $string=""; for($i=0; $i <= $numlines; $i++) $string .= $lines[$i]; //write to file and close stream fwrite($fp, $string); fclose($fp);[/code] I also tried to change permissons using [code]chmod ("/Test2", 777);[/code] but I recieved the error message: Warning: chmod() [function.chmod]: open_basedir restriction in effect. File(/Test2) is not within the allowed path(s): (/home/folder:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/folder/public_html/chmod.php on line 3 I'm getting a little frustrated now because I can't even delete the folders I've created without contacting my hosting company! Many thanks...
  4. Is it possilbe to do something like this? [code]<?php $data = 'New company 1'; ?> <form action="../code/validate_insert.php" method="post"> <input type="hidden" name="company" value=" <?php $data ?>" /> <input type="image" name="submit" src="../images/submit_button.jpg" /> </form>[/code] I've been told headers and sessions will do it,  but every time I try and implement them I get never ending header errors... Cheers
  5. Hey, I'm sorry if this is a novice question... How is the best way to transfer a variable to another page... For example getting a variable $ex1 on 'index.php' to $ex1 on 'form.html', with the files being located in the same directory folder... Maybe using headers? Cheers
  6. Worked a treat! Thanks loads...
  7. Hey, I'm using the following code to insert a page at a particular location on my web server. What I actually want to do is copy the code that is contained within a file 'example.php' to newform.php, say about 50 lines of code. [code]$fp = fopen ("new_folder/newform.php", 'w'); fwrite ($fp, 'code here'); fclose($fp);[/code] At the moment the code obviously only inserts 'code here' into newform.php. But I don't want to just stick a massive string in instead of 'code here' so does anyone know of a better way to achieve my goal. Many thanks and any help would be much appreciated...
  8. thanks loads, will give it a go...
  9. When I upload a telephone number field to an SQL database, for example 01898543251, the leading zero is removed and becomes 1898543251. Is there a numeric type that keeps the leading zero or does it have to be inserted as a type of string? Any help would be much appreciated... Cheers,
  10. [b]THE UPLOAD CODE:[/b][code]<?php $uploadDir = 'C:\Program Files\xampp\htdocs\Sites\Test\uploads\#'; if(isset($_POST['upload'])) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } print "File uploaded to $filePath"; if ($dbc = mysql_connect ('localhost', 'us', 'pw)) { print '<p>Successfully connected to MySQL.</p>'; if (@mysql_select_db ('client_db')) { print '<p>The database has been selected.</p>'; } else { die ('<p>Could not select the database because: <b>' . mysql_error() .'</b></p>'); } if(!get_magic_quotes_gpc()) { //$fileName = addslashes($fileName); //$filePath = addslashes($filePath); } $query = "INSERT INTO upload2 (name, size, type, path ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); mysql_close(); echo "<br>Files uploaded<br>"; } } ?>[/code] [b]view path/image code:[/b][code]<?php ini_set ('display_errors',1); error_reporting (E_ALL & ~E_NOTICE); //Connect and select---------------------------------------------------------- if ($dbc = mysql_connect ('localhost', 'tom', 'ickellious')) { if (!@mysql_select_db ('client_db')) { die ('<p>Could not select the database because: <b>'. mysql_error().'</b></p>'); } } else { die ('<p>Could not connect to MySQL because: <b>'. mysql_error().'</b></p>'); } //---------------------------------------------------------------------------- $query = "SELECT path FROM upload2"; $result = mysql_query ($query); print "$result"; /*$query = 'SELECT * FROM upload2 ';//ORDER BY entry_ID DESC if ($r = mysql_query ($query)) { while ($row = mysql_fetch_array ($r)) { print "<p>{$row['id']}<br/> {$row['name']}<br/> {$row['type']}<br/> {$row['size']}<br/> {$row['path']}<br/> </p>"; } }*/ mysql_close(); ?>[/code] [b]I have commented out some stuff I've tried but the query ran from the sql console returns the correct value but when it is ran through php, the wrong stuff is output... Cheers[/b]
  11. Hi, I've written a file path to a database but when I look at the records in the database it has erased the slashes indicating the change of folders... for example... C:\new\folder\filename.ext becomes c:newfolderfilename Do I have to use addslashes() in some way?  I have tried it but nothing seems to be changing. Also, when I use php to retrieve the database information instead of returning 'c:newfolderfilename' it displays 'Resource id #3'. Any help would be very much appriciated... Cheers
  12. many thanks, will give it a go...
  13. I have been searching the web for ages and found loads of tutorials on how to save a jpeg into a blob using mysql but many articles say that access time to and from the database are slow. Does anyone know of a simple working tutorial that allows you to upload a file to a folder on web server and the save location of this file (a string) in an sql database so it can be referenced and displayed simply in another web page? Apologies if this has problem has been posted many times before... Any help would be much appreciated... Cheers.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.