PHP - Php Make File In System Dir
Hello, I'm trying to create a file in my home dir and in my etc folder but I keep getting permission denied.
I am doing this
$myFile = "/home/ng/http/uid.txt";
Similar TutorialsI havent included the whole title as it wouldnt let me but I was wondering if someone could help me on this? I know this is possible as torrentflux caters for this but unsure of where to start. I dont want to allow file or directory uploads or creation in my /etc/php.ini file (this is turned off). Yet then torrentflux allows me to link a torrent from an external source (using legal downloads of course ) but then it uploads it on my server and creates folders on a per user basis. How is this possible can someone give me some pointers please? I look forward to any replies, Jeremy. I would like to make a budget system where the user enter their preferred budget, then the system will generate a package based on the budget enter, system will generate the budget package based on the database. For example, i have 4 categories - flower, cake, hotel & bridal house user enter budget of $100, system will then check through the database, come out with a package which include each of the categories above. output should be flower:30 cake:20 hotel:30 bridal house:20 how should i do that? what math should i use? probability? i need a download system like www.filehorse.com. can plz tell me how? its generate link 4 download for limited time. without giveing hot link. plztake a look and help me out
Hey guys first of all I got 3 files - index.php require_once('/libs/template.class.php'); $template = new Template; $template->assign("title","test"); template.php <?php echo $title; ?> template.class.php function assign($var, $val) { $var = $val; } I'm trying to assign a variable in index.php, then recall it in the template.php, how would I go about this? Thank you! I have a database table of plants, one of chemicals, one of products, one of illnesses. Each table is connected, for example lets say opium poppies. They contain the chemical morphine. Morphine is used in painkiller products. Its used to treat pain and other illnesses. On the opium poppy page, I want to list all the chemicals found in the poppy. All the products (i.e. opium, laudanum) made from the poppy. All the illnesses which are treated with the poppy. Users need to be able to edit this page, and enter chemicals, products or illnesses that are related to this plant. They also need to be able to edit the info on the page.
Making database relations is a pain in the ass with CakePHP. I don't want to waste any more time so I'm thinking maybe making it as a wordpress plugin is the way to go. How would you go about this? Is there an easier way than wordpress, like a better CMS, or framework? If I use wordpress, should I do all the DB interactions with AJAX to avoid having to interact with the DB through wordpress (this gave me massive trouble in the past since I had my data in an external db)?
Hi everyone... I would like to implement a questionnaire/survey system that has only two Answers (Yes /No). Basically, this questionnaire system will be widely used on Mobile Phones. It will be looking something like this below: http://awardwinningfjords.com/2009/06/16/iphone-style-checkboxes.html Lets say a user selects a response as No (Using the above slider button for a question). That response should be recorded in the database with User Details + Time Stamp. Also, I would like to generate a report for each question (Responses of Multiple Users) and a report at a User Level for the entire questionnaire/survey (s). Can some one guide me the fastest & easiest way to achieve this? I'm a new learner of PHP. Regards Sandeep during lesson time we're developing php systems and our topic is virtual storage like dropbox, google drive etc. My teacher has now set the task to enable the ability to share files within the server but also restrict access within the server folder. I'm being taught MySQL however I've read a lot about PDO being better and decided to use this method to try and get a higher grade for my project although I'm having difficulty understanding how to go about it what i want to achieve is:
creating file sharing capability (i.e. students can share group projects)
restricting users (only those working on a particular document can view it)
don't worry this is not for my own benefit I'm just trying to get a grade here, I mainly just want advice on what I need I've read quite a bit but unfortunately I'm more of a visual learner.
HI all, this is a strange request so bear with me. I have setup a server on my local machine, what I want to do is scrape info off the real server out on the internet in some of the pages. I have that working using curl for different domains, but the issue is I have a 127.0.0.1 host entry for the domain in question because the local server name has to match the real server name for the application to run. I can get the real IP using a shell ie: echo exec('nslookup example.com 1.1.1.1'); but I don't know how to get curl to use that IP or force curl to use a different name server, any ideas?
CURL code:
thanks in advance!!
$url = "http://example.com/index.php"; $fields = [ 'id' => '1234' ]; $fields_string = http_build_query($fields); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); echo $result;
I have been following a tutorial to create my first php application, a file (image) uploading system. I am hoping to add it to my site, http://www.kalam1ty.com/upload.php I have read through the code multiple times and cannot find out what is wrong. I have tried to fix this for about half an hour now and cannot seem to find where the code is wrong. It does not generate any errors and passes all of the checks that I wrote, it just does not upload the image. Nothing in the upload part of the script looks off to me, but I am a PHP newbie, and am not 100% sure. Here is the whole page's code: Code: [Select] <?php if(isset($_FILES['image'])) { $errors = array(); $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $file_name = $_FILES['image']['name']; $file_ext = strtolower(end(explode('.', $file_name ))); $file_size = $_FILES['image']['size']; $file_tmp = $_FILES['image']['tmp']; if(in_array($file_ext, $allowed_ext) === false) { $errors[] = 'Extionsion not allowed.'; } if($file_size > 10485760) { $errors[] = 'File too large. Must be under 10MB.'; } if(empty($errors)) { //upload file if (move_uploaded_file($file_tmp, 'uploads/images'.$file_name)) { echo 'File uploaded to kalam1ty.com/uploads/images/'; } } else { foreach ($errors as $error) { echo $error, '<br>'; } } } ?> <html> <head> <title> Kalam1ty - Home </title> <link rel="stylesheet" type="text/css" href="style.css" /> <link href='http://fonts.googleapis.com/css?family=Anonymous+Pro' rel='stylesheet' type='text/css'> <link rel="shortcut icon" href="/home/corona/Development/Web/favicon.ico" type="image/x-icon" /> <meta name="google" value="notranslate"> </head> <body> <div id="EncBG"> <div id="Navbar"> <a href="index.php">Home</a> <a href="downloads.php">Downloads</a> <a href="upload.php">Upload</a> <a href="contact.php">Contact</a> </div> <div id="Enc1"> <div id="Content"> <h2>Upload Files</h2> <form action='' method='POST' enctype='multipart/form-data'> <p> <input type='file' name='image'> <input type='submit' value='Upload'> </p> </form> </div> </div> <div id="Footer" class="whitetext" align="center"> <b><i> <a href="index.html">HOME</a> // <a href="downloads.html">DOWNLOADS</a> // <a href="#">OTHER</a> </b></i><br> <img src="smlogo.png" alt="Kalam1ty"/> </div> </div> </body> </html> Thank you guys very much if you can help me! Hi Everyone, this is a very old code. I know I have to change the 'addslashes' method in this code. I also just changed the code using 'mysqli'. There are two files to upload the images to a gallery, preexport.php and export.php. The upload works up to five images. if I choose 6 or more and press add images, the browser refreshes itself and the upload won't happen. All the fields on the form clears itself and no errors shows up...can you please take a look and help me correct this problem? Here are the two files...
export.php
<?php include("config.inc.php"); if ($_SERVER['REQUEST_METHOD'] == "POST") { include("config.inc.php"); if(!$_POST) { header("Location: preexport.php"); exit(); } // initialization $result_final = ""; $counter = 0; // List of our known photo types $known_photo_types = array( 'image/pjpeg' => 'jpg', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', 'image/bmp' => 'bmp', 'image/x-png' => 'png' ); // GD Function List $gd_function_suffix = array( 'image/pjpeg' => 'JPEG', 'image/jpeg' => 'JPEG', 'image/gif' => 'GIF', 'image/bmp' => 'WBMP', 'image/x-png' => 'PNG' ); // Fetch the photo array sent by preexport.php $photos_uploaded = $_FILES['photo_filename']; $filename[]= $photos_uploaded['name'][$counter]; //print_r($photos_uploaded); $photo_caption = $_POST['photo_caption']; // Fetch the photo caption array $photo_description = $_POST['photo_description']; // Fetch the photo caption array $photo_keyword = $_POST['photo_keyword']; while( $counter <count($_FILES['photo_filename']['tmp_name']) ) { if($photos_uploaded['size'][$counter] > 0) { if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types)) { $result_final .= "File ".($counter+1)." is not a photo<br />"; } else { /*print "HHHHHH\n"; print "Counter is $counter : "; print $photos_uploaded['name'][0]; print $photos_uploaded['name'][1]; print "Photo caption is $photo_caption[$counter]"; */ mysqli_query( $mysqli,"INSERT INTO gallery_photos ( `photo_filename`, `photo_caption`, `photo_description`, `photo_keywords`, `category_name` ) VALUES( '".addslashes($photos_uploaded['name'][$counter])."', '".addslashes($photo_caption[$counter])."', '".addslashes($photo_description[$counter])."', '".addslashes($photo_keyword[$counter])."', '".addslashes($_POST['category'])."')" ) or die(mysqli_error() . 'Photo not uploaded'); // $new_id = mysqli_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; //$filename = $photo_filename[$counter].".".$extention; //$filename = $new_id.".".$extention; // mysqli_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); // Store the orignal file copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$photos_uploaded['name'][$counter]); // Let's get the Thumbnail size $size = GetImageSize( $images_dir."/".$photos_uploaded['name'][$counter] ); if($size[0] > $size[1]) { $thumbnail_width = 200; $thumbnail_height = (int)(200 * $size[1] / $size[0]); } else { $thumbnail_width = (int)(200 * $size[0] / $size[1]); $thumbnail_height = 200; } // Build Thumbnail with GD 1.x.x, you can use the other described methods too $function_suffix = $gd_function_suffix[$filetype]; $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$photos_uploaded['name'][$counter] ); $sharpenMatrix = array ( array(-1.2, -1, -1.2), array(-1, 8, -1), array(-1.2, -1, -1.2) ); // calculate the sharpen divisor $divisor = array_sum(array_map('array_sum', $sharpenMatrix)); $offset = 0; if($source_handle) { // Let's create an blank image for the thumbnail $destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height ); // Now we resize it ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] ); } // Let's save the thumbnail $function_to_write( $destination_handle, $images_dir."/tb_".$photos_uploaded['name'][$counter], 100 ); ImageDestroy($destination_handle ); // $result_final .= "<img src='".$images_dir. "/tb_".$photos_uploaded['name'][$counter]."' /> File ".($counter+1)." Added<br />"; } } $counter++; } // Print Result echo <<<__HTML_END <html> <head> <title>Photos uploaded</title> </head> <body> $result_final </body> </html> __HTML_END; } ?>preexport.php <?php include 'config.inc.php'; $photo_category_list = ''; $photo_upload_fields = ''; $counter = 1; // If we want more fields, then use, preexport.php?number_of_fields=9 $number_of_fields = (isset($_GET['number_of_fields'])) ? (int)($_GET['number_of_fields']) : 9; // Firstly Lets build the Category List $result = mysqli_query($mysqli,'SELECT category_name FROM gallery_category'); /*if($result === FALSE) { die(mysqli_error()); // TODO: better error handling }*/ while($row = mysqli_fetch_array($result)) { $photo_category_list .= <<<__HTML_END <option value="$row[0]">$row[0]</option>\n __HTML_END; } mysqli_free_result( $result ); // Lets build the Image Uploading fields while($counter <= $number_of_fields) { $photo_upload_fields .= <<<__HTML_END <tr><td> Photo {$counter}: <input name="photo_filename[]" type="file" /> </td></tr> <tr><td> Caption: <textarea name="photo_caption[]" cols="50" rows="1"></textarea> </td></tr> <tr><td> Description: <textarea name="photo_description[]" cols="50" rows="4"></textarea> </td></tr> <tr><td> Keyword: <textarea name="photo_keyword[]" cols="50" rows="4"></textarea> </td></tr> __HTML_END; $counter++; } // Final Output echo <<<__HTML_END <html> <head> <title> Rajeev lets upload photos!! </title> </head> <body> <form enctype="multipart/form-data" action="export.php" method="post" name="export_form"> <table width="90%" border="0" align="center" style="width: 90%;"> <tr><td> Select Category <select name="category"> $photo_category_list </select> </td></tr> <!—Insert the image fields here --> $photo_upload_fields <tr><td> <input type="submit" name="submit" value="Add Photos" /> </td></tr> </table> </form> </body> </html> __HTML_END; ?> hello and good day dear Linux-experts, i want to install a new opensuse linux on a notebook. i want to upgrade is the following: this one: Akoya P 6512 15" OpenSuse 13.1: AMD Athlon X2 P320, 2,10 GHz, 4 GB 320 GB hdd-drive what is wanted: i want to do a total fresh installation i want to have not tooo much partitions! i only want to run opensuse 13.2 i want to have some kind of native linux partitions - such as ext 4 - # what do you suggest - should go with the new default BTRFS file system?!? well to begin with the beginning: i applied the following commands a. lsblk b. fdisk -l see the results,,,, ; linux-c5sz:/home/martin # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465,8G 0 disk ├─sda1 8:1 0 4G 0 part [SWAP] ├─sda2 8:2 0 102M 0 part ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 2G 0 part ├─sda6 8:6 0 4G 0 part ├─sda7 8:7 0 10G 0 part ├─sda8 8:8 0 20G 0 part / └─sda9 8:9 0 389,6G 0 part /home sr0 11:0 1 1024M 0 rom and the following fdisk -l linux-c5sz:/home/martin # fdisk -l Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors Units = Sektoren of 1 * 512 = 512 byte Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xb8fa3ecd Gerät boot. Anfang Ende Blöcke Id System /dev/sda1 63 8385929 4192933+ 82 Linux swap / Solaris /dev/sda2 8385930 8594774 104422+ 83 Linux /dev/sda4 * 8803620 976768064 483982222+ 5 Extended /dev/sda5 8803683 12996584 2096451 83 Linux /dev/sda6 12996648 21382514 4192933+ 83 Linux /dev/sda7 21382578 42347339 10482381 83 Linux /dev/sda8 117821440 159766527 20972544 83 Linux /dev/sda9 159768576 976766975 408499200 83 Linux linux-c5sz:/home/martin # subsequently the questions; which partition logic should i choose. what is wanted: i want to have not tooo much partitions! i only want to run opensuse 13.2 note: i want to erase all the existing partition logic /(that is currently existing) i do this with Gparted. which partitions should i take? which file system ? i am curious to get to know your ideas Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 Hello, Is there a function to make a PHP file explicitly to be used as an include only? Or would it just be easier to set a variable in the parent page and test for it in the include page? I just wanted to make sure there wasn't a more efficient way than using the latter method. Thanks, Carson I have a function to writes data I want to make sure it was successful. my function: Code: [Select] function save_ini_file($filename,$content) { $File = "ini_files/". $filename . ".ini"; echo $File; $Handle = fopen($File, 'w'); $info = $content; fwrite($Handle, $info); fclose($Handle); return true; } the if statement that calls the function. Code: [Select] if(!save_ini_file($serial,$data)) { echo "did not write"; }else{ echo "did write"; } the file is being created but I am getting the "did not write" echoed I'm having a problem with getting the timestamp to attach to the filename. Currently when it's uploaded in the database it says $timestamp in front of the filename instead of the time. Scroll down towards the bottom of the code to see it. Thanks for your help! $username = $_GET['username']; $item_id = $_GET['id']; define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'thumb' ][ 'tmp_name' ]; $timestamp = time(); // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // header( 'Content-type: image/jpeg' ); imagejpeg( $desired_gdim, "image_files/".'$timestamp'.$_FILES["thumb"]["name"] ); mysql_connect("localhost", "root", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $timestamp = time(); $item_image = '"$timestamp"'.$_FILES['thumb']['name']; $sql="UPDATE product SET thumb='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); And how can I make it so if it does already exist, it doesn't over-write information already in it? Thanks ok .. so I have this object and I want to make a tab delimited text file from it. here's what I have so far. function create_tab_file_from_object($the_object) { $string = ''; foreach($the_object as $val) { $string .= $val.'\t'; } //drop last tab $string = substr($string,0,-2); filename = 'test_file_pickup.txt'; $fp = fopen('/filepath/'.$filename,'w'); fwrite($fp,$string); fclose($fp); } when i run this i get a text file that looks something like this field1\tfield2\tfield3\t ... and so on. How do I get php to make an actual tab delimited file I can open in notepad or excel or whatever.. Thanks in advance, C I know it needs a for loop, but i don't know where in the code i should be putting it? Code: [Select] function check_input($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number if (!is_numeric($value)) { $value = "'" . mysql_real_escape_string($value) . "'"; } return $value; } $_POST = array_map('check_input', $_POST); $sql="INSERT INTO testimonials (CustomerName, Town, Testimonial, SortOrder, Images) VALUES ({$_POST['customername']}, {$_POST['town']}, {$_POST['testimonial']}, {$_POST['sort_order']}, '$imgname' )"; } if (!mysql_query($sql,$con)) { die("<br>Query: $sql<br>Error: " . mysql_error() . '<br>'); } echo "<p align=center><b>1 testimonial added</b></p>"; mysql_close($con); Thanks in Advance, Steve |