PHP - 777 Upload Permission Problem
this script is supposed to save my $csvfile to a .sql file name $ouputfile into a folder called files/
$csvfile = $_FILES['file']['name']; //form from another folder $save = 1; $outputfile = "output.sql"; here is the save script if($save) { chmod($csvfile, 0777); if(!is_writable($outputfile)) { echo "File is not writable, check permissions.\n"; //when i execute this script, it goes in here } else { $file2 = fopen($outputfile,"w"); if(!$file2) { echo "Error writing to the output file.\n"; } else { fwrite($file2,$queries); fclose($file2); } } Similar TutorialsSo i am on a shared host and it seems that only 777 allows me to upload images on a certain folder , not 755 , just 777... is it because of the shared host or thats how it works? PS: i really didnt know where to post it so if a mod can move it , i'd appreciate it. I am trying to run the following code to upload a file. (WAMP using Win XP). Once I select the file and click submit I get the error: "Forbidden... You don't have permission to access /< on this server." with URL http://localhost/<?=$PHP_SELF?> Code is below: <form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data"> <br/><br/> Choose a file to upload:<br/> <input type="file" name="upload_file"> <br/> <input type="submit" name="submit" value="submit"> </form> TIA Hi I have an image uploading script that won't upload images... It worked at one point when i had folder permission at 0777 but i was told that is risky so i changed it to 0775 Now it won't work and i can't use 0777. Any one know what i need to do to get it to work? This is my script: Code: [Select] <?php $salt = 35322232414; $name = $salt.$safe; $name = md5($name); if(isset($_POST['submit'])){ if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 1000000)) { if ($_FILES["file"]["error"] > 0) { echo $_FILES["file"]["error"]; } else { $filename = md5(serverdate()) . $_FILES["file"]["name"]; if (file_exists("userimages/".$name."/".$filename)) { echo "Image already uploaded!"; } else { if (is_dir("userimages/".$name) == FALSE){ mkdir("userimages/".$name, 0775); //permissions } move_uploaded_file($_FILES["file"]["tmp_name"], "userimages/".$name."/" . $filename); echo "Image has been uploaded!"; } Error i get: Quote Warning: move_uploaded_file(images/73640de25b7d656733ce2f808a330f18/7fc9cb9cf5ae1f7a5dd9105d3f9559fb_63.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in uploadfile.php on line 41 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpjrX3SO' to 'images/73640de25b7d656733ce2f808a330f18/7fc9cb9cf5ae1f7a5dd9105d3f9559fb_63.jpg' in uploadfile.php on line 4 Im in the process of setting up a social media site , Just switched from basic hosting to Dedicated Server Everything was working till i switched . I have a basic join forum and email activation , On the register.php file it tell script to make a directory mkdir into member/folder like this below, But it will make the folder for the id of that user but will not let them upload any images?. At first it wouldnt even make a folder but i found out it was a permissions issue with my server i fixed it , im guessing the upload is also a permission's issue ? But the script automaticly make the members/"$id" folder and i dont know how to set permission for auto create folder that if i even have to ? so confused. (BEGGGGINGG !! FORRRRR HELPPPPPPPPPPPPPPPPPPPP! Im running a dedicated server with godaddy, On centOs w/ Plesk Panel 9.3.0 ------------------------------------------------------------------------------------------- $id = mysql_insert_id(); // Create directory(folder) to hold each user's files(pics, MP3s, etc.) mkdir("members/$id", 0755); Hello I built a component for a non-profit organisation which want to use the 404page to promote several charities. In order to do that I want to place a file 'error.php' in the map 'templates/system'. I use the RENAME function for that. So far so good. On many sites it works fine, but on other sites I get an error on the rename function. The user-id and the group-id of the script I use are the same as the uid's of 'templates/system'. So there shouldn't be a problem. If I add public write to the filepermissions of 'templates/system'/ with Filezilla the error disappears. But I can't do that with the php chmod function, again because of too less priviliges. HELP, I can't find an explanation for that and that's driving me crazy. thanks in advance I am getting this error Warning: ftp_put() [function.ftp-put]: Can't open that file: Permission denied in /home/chris/public_html/site-name/wp-content/setup.php on line 62 Code: [Select] $conn_id = ftp_connect($host, 21) or die ("Cannot connect to host"); ftp_login($conn_id, $usr, $pwd) or die("Cannot login"); // turn on passive mode transfers (some servers need this) // ftp_pasv ($conn_id, true); $upload = ftp_put($conn_id, $file[0], $file[1], FTP_ASCII); print (!$upload) ? die('Cannot upload') : 'Upload complete'; print "\n"; The permissions to the file is 0644, if I change it to 0777 ftp_put complains and says the file is not found. How can I ftp this file? What is going on? Thanks, Chris Hi. I'm using SimpleImage.php to do some basic image manipulation. The code is here http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php, but I don't think all the details are important. Basically, I'm trying to read and image and save it with a different name. I'm really new with this stuff, so it's probably something simple. Anyway, here is the code throwing the error, $image_info = getimagesize($filename); where $filename is a string containing the path to the image I want to load, e.g. $filename="images/picture.jpg"; It's throwing a "Read Error!" I know that the path is correct. In fact I first check if the file is there using is_file($filename); and it returns true. I'm guessing that maybe php does not have "permission" to read this file. The permissions for the file are -rw-r--r-- 1 www-data www-data 80211 2011-04-20 16:19 picture.jpg Looks like everyone has "read" permission, so I don't see what the problem is. Also, the permissions of the folder and all parent folders are 777. Not sure what the problem is. I might be way off by guessing that it is a permissions problem. Any help would be great. Thanks. Also, I was wondering if there is a way for this forum to email me whenever there is a reply to my posts. I can't seem to find the option anywhere. I have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? Hey Guys, can somebody please have alook at my code, when I don't have the mysql stuff in it works not problem, when I add the mysql it does not want to upload the file. Thanks Code: [Select] <?php // Where the file is going to be placed $target_path = "../uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { { $con = mysql_connect("localhost","******", "*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("******", $con); mysql_query("INSERT INTO table (sname, smonth, sday, syear, sdload) VALUES ('$sname', '$smonth', '$sday', '$syear', '$fileupload')"); mysql_close($con); echo "Successful<BR/>"; echo "<a href=index2.php>Return to admin section</a>"; } } else{ echo "There was an error uploading the file, please try again!"; } ?> When I upload files larger than appx 18M it says that the file was uploaded but it isnt. Is there snippet of code that i could put in the script to show me the upload error ? Or does anyone know what could be causing this. My php.ini settings are as follows max upload size = 50M max post size = 100M execution time = 2400 input time = 2400 I thought initially maybe it was timing out so i increased the input and the execution time value. But its still doing the same thing. -SB Hi Everyone, I have a small problem and try to learn from all the help i get here. I have a form that gathers info, emails and inserts info into the database, everything works fine except the file doesnt upload and the file name does not go into the database, instead i get /recruitment in the file field of the databse, instead of recruitment/uploadedfile.pdf Code Below, please help, <?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 == ''){ $add="recruitment/".$_FILES[userfile][name]; $cleaned = stripit($add); $add2 = "../".$cleaned; 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 = '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 = "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 Consultant will contact you shortly.<br /> <br /> </td> </tr> </table>'; }else{ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } echo ' <form id="form" name="Contact Form" method="post" action="'.$_SERVER['PHP_SELF'].'?action=recruit"> <table width="489" border="0" cellspacing="5" cellpadding="0"> <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 have use apache server with PHP installed on it,i created one directory through php coding it get created but it has permission ( drwxr-sr-x 3 www-data www-data 4096 Feb 26 04:54 Merchantid_30) my other directories has ubuntu:ubuntu permission, I want to write on my directory but www-data wont allow me to write on it,giving 777 permission through chmod is risky, can i create directory through php but its default permission is set to be ubuntu:ubuntu instead of www-data ? what changes i need to do in coding?
I have a page for image uploads and I just realized it will only work if a user already has on picture uploaded. If they don't it won't work. The ones that do fail some photos anyway which is probably that they don't pass the image check but when I put echoes in there to trace what happens any user with an empty gallery can't upload a photo because the page says there is no file in the $_FILES['image']['name'] variable. Here are the initial conditions and the form (leaving out the image processing etc since that works): Code: [Select] if (!isset($_SESSION['user'])) die("<br /><br /> You need to log in to view this page"); $user = sanitizeString($_SESSION['user']); $view = sanitizeString($_GET['view']); $dir = './grafik/users/'.$user.'/big/'; $files = scandir($dir); $len = count($files); $nr= $len-1; $maxPhotos = 8; if ($view == $user) { echo "view is user"; if(!file_exists("grafik/users/$user")) { mkdir("grafik/users/$user"); mkdir("grafik/users/$user/big/");} } if (!isset($_FILES['image']['name'])) echo "There is no file <br />$dir - $user - $nr"; if (isset($_FILES['image']['name'])) { echo "<br />...is a file <br />$dir - $user - $nr"; $photoName="$dir$user$nr.jpg"; move_uploaded_file($_FILES['image']['tmp_name'], $photoName); $typeok = TRUE; .... <form method='post' action='gallery.php?view=$user' enctype='multipart/form-data'> Upload another photo: <br /> Max $maxPhotos allowed, max filesize 2Mb <br /> <input type='file' name='image' size='10' /><br /> <input type='submit' value='Upload' /> </form> I can't see why it wouldn't let me but I have a feeling someone here knows why. Hi everybody, I have recently change to a new server, and have some problem with a script for uploading files on my new server. Script is an old which I have updated with new php command, <? not accepted in new server. Scripts shall upload picture to folder in server and write information to database From form script I am saving my upload Code: [Select] <input type="hidden" name="Mode" value="EditMapProperty" /> <input type="hidden" name="Old_Map" value="<?php echo $Property->Get_Map();?>" /> In my php script I do elseif($Mode=="EditMapProperty"): $Map_name = $HTTP_POST_FILES['Map']['name']; $Property=new Property($PropertyID); $ReferenceNo=$Property->Get_ReferenceNo(); if($Map!=""): $DeleteMap=$Dir_MapProperty_Admin."".$Property->Get_Map(); @unlink($DeleteMap); endif; if($Map_name==""): $Map=$Old_Map; else: copy($HTTP_POST_FILES['Map']['tmp_name'], $Dir_MapProperty_Admin."".$ReferenceNo."-".$Map_name); $Map=$ReferenceNo."-".$Map_name; endif; $Property->EditMap($Map); //Update database information echo "<meta http-equiv=\"refresh\" content=\"0;URL=$Redirect2?p=property_details&PropertyID=$PropertyID\">"; () Can any help if there are any PHP problem in this coding. Kind Regards Tom hi i have wrote this code for uploading an image this is my main code <?php $lastimage2 = mysql_query("SELECT * FROM images WHERE id=$view"); $li2 = mysql_fetch_assoc($lastimage2); if ($page=="P8"&$view>0) { echo "<table class=roung bgcolor='#000000'><tr><TD><img src=uploaded/$li2[picname] width='760' height='540'></td></tr></table>"; include 'picclicks.php'; echo "<tr><td>Views: $clicks2 </td></tr>"; } else { if ($_SESSION['user']) { If ($imagereport='1') { } echo" <table bgcolor='#000000' class=round><tr><td class=ach> <form action='index.php?variable=".$page."&fun=upload' method='POST' enctype='multipart/form-dat'> <input type='file' name='myfile'> <input type='submit' value='Upload'> </td></tr></table></form> "; } else { echo "Please Login to upload new photos!"; } ?> then i have this for imageupload.php <?php if ($_FILES) { $username = $_SESSION['user']; $date =time(); $name = $_FILES["myfile"]["name"]; $type = $_FILES["myfile"]["type"]; $size = $_FILES["myfile"]["size"]; $temp = $_FILES["myfile"]["tmp_name"]; $error = $_FILES["myfile"]["error"]; $hs=$_POST['High Score']; $g=$_POST['Glitch']; $f=$_POST['Funny']; $o=$_POST['Other']; $tags = new Array(); foreach($_POST['tag'] as $tag){ if($tag){ tags[] = $tag; } } $tag = implode(',',$tags); if ($error > 0 ) die("Error uploading file! Code $error."); else { if ($type =="image/jpeg") { include 'connect.inc'; move_uploaded_file($temp,"uploaded/".$name); mysql_query("INSERT INTO images VALUES('','$name','','$username','$date','0','0','0','0','0','0','0','0')"); $uploadreport='1'; } else { } } } else { } ?> my database is set right, and this is what i have in my index file if ($fun=="upload") { include 'imageupload.php'; } when i click upload it directs it to index.php?variable=P8&fun=upload but nothing shows up on screen if u need more details please ask cheers matt Hello Im trying to upload mp3s from a form. In the form I have the MAX_FILE_SIZE set at 90000000 (so big to make sure it wasn't my maths). I have checked with phpinfo() and the max upload is set at 8mb. The mp3s will be between 3-4mb in size. I have uploaded small mp3's successfully (440k) so i know the script is working fine, however when i try to upload one at around 3mb it fails, even tried different file sizes in the same ball park size. I suspect the server is blocking them. Any ideas on a fix? Thank you. No script posted as i say its all working. hello everyone....i am new for this script, hope u guys able to help me. Thank you in advance! im using xampp for localhost, all .php file i place it in xampp\htdocs ( i create a uploads folder outside the htdocs, c:\xampp\uploads) This is the error message i get after i upload the file: Notice: Undefined variable: FILES in C:\xampp\htdocs\upload_file.php on line 15 Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\upload_file.php on line 15 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpAE.tmp' to '../uploads/' in C:\xampp\htdocs\upload_file.php on line 15 Your file could not be uploaded because: Something unforeseen happened.. following is my upload_file.php script , i highlighted on line 15: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Upload a File</title> </head> <body> <?php ///Script - 11.4 - upload_file.php /* This script displays and handles an HTML form. this script takes a file upload and stored it on the servers */ if(isset($_POST['submitted'])) { //Handle the form //Try to move the upload file: if (move_uploaded_file ($_FILES['thefile']['tmp_name'],"../uploads/{$FILES['thefile']['name']}")){ print '<p>Your file has been uploaded.</p>'; }else { //problem!! print '<p style="color:red;">Your file could not be uploaded because: '; ///print a message based upon the error: switch ($_FILES['thefile']['error']) { case 1: print 'The file exceeds the upload_max_filesize setting in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'The temporary folder does not exist.'; break; default: print 'Something unforeseen happened.'; break; } print '.</p>'; /////complete the paragraph. } // End of move_uploaded_file()IF } // End of submission IF //Leave PHP and display the form: ?> <form action="upload_file.php" enctype="multipart/form-data" method="post"> <p>Upload a file using this form:</p> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <p><input type="file" name="thefile" /></p> <p><input type="submit" name="submit" value="Upload This File" /></p> <input type="hidden" name="submitted" value="true" /> </form> </body> </html> Hi, I can't believe after more then a year I'm stuck with the simplest upload script. Here's my code: <?php if( isset($_POST['upload']) ){ $uploaddir = "uploads/"; $uploadfile = $uploaddir.$_FILES['fileupload']['name']; if( move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile) ){ echo "Upload OK!"; }else{ echo "Upload FAILED!!!"; } }else{ ?> <form action="<?php $_SERVER['PHP_SELF'] ?>" name="upload" method="post"> <input type="file" name="fileupload" /> <input type="submit" name="upload" value="upload" /> </form> <?php } ?> this is the simplest php upload script that you can find, though the least secure one (it's for a local pc project). When I try to upload any file it gets to my else statement. Anyone an idea why? I don't see it Thanks! Hi Guys I have this PHP Upload Scripts below which uploads file of customers into the customers folder and at the same time inserts the file path into the database. The problems is for name like O'hare or O'neil its uploads into the customers folder but does not insert the file path into the database - probably because of the " ' " apostrophe From the code below is there anyway I can deal with this issue? Thanks alot Code: [Select] <?php //This php block of code will takecare of inserting the upload variables into the db if(isset($_POST['submitbutton'])) { $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; $target_path = $target_path . basename( $_FILES['upload']['name']); $manager= mysql_real_escape_string($_POST['username']); $upload = $_FILES['upload']['name']; $check_id = mysql_real_escape_string($_POST['id']); $submitbutton= mysql_real_escape_string($_POST['submitbutton']); if($submitbutton) { if($manager&&$upload) { if (file_exists($target_path)) { echo $_FILES["upload"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path); echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"]; $insert=mysql_query("INSERT INTO img_up (username,upload,id,target_path,img_date) VALUES ('$manager','$upload','$check_id','$target_path', now()) "); // Where the file is going to be placed $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['upload']['name']); $target_path = 'customerUploads/' . $check_id . ', ' . $c_name . '/'; $target_path = $target_path . basename( $_FILES['upload']['name']); if (file_exists($target_path)) { echo $_FILES["upload"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["upload"]["tmp_name"],$target_path); echo "Stored in: " . 'customerUploads/' . $check_id . ', ' . $c_name . '/' . $_FILES["upload"]["name"]; } } } else { echo "There was an error uploading the file, please try again!"; } } header("location: mainupload_complete.php?id=$check_id"); } ?> I am working on a file upload that stores the image in the database. my upload field is this: Code: [Select] <input type="file" name="image1[]" /> and my php to process the file and upload it is this: $maxsize = 100000; if(is_uploaded_file($_FILES['image1']['tmp_name'])) { //check the file is less than the maximum file size if($_FILES['image1']['size'] < $maxsize) { //prepare the image for insertion $imgData =addslashes(file_get_contents($_FILES['image1']['tmp_name'])); $imgData = addslashes($_FILES['image1']); //get the image info.. $size = getimagesize($_FILES['image1']['tmp_name']); $id = $name.'_'.$SKU; //our sql query $sql = "INSERT INTO Images ( imageID , Type ,Image, Size, FileName, DateAdded, Category, SKU. Description) VALUES ('".$id."', '".$size['mime']."', '".$imgData."', '".$size[3]."', '".$_FILES['image1']['name']."', NOW(), Fabric, '".$SKU."', '".$desc."'"; echo $sql; // insert the image if(!mysql_query($sql)) { echo 'Unable to upload file'; } } } else { // if the file is not less than the maximum allowed, print an error echo '<div>File exceeds the Maximum File limit</div> <div>Maximum File limit is '.$maxsize.'</div> <div>File '.$_FILES['image1']['name'].' is '.$_FILES['image1']['size'].' bytes</div> <hr />'; } at first the sql just wouldn't work. Now I get this error every time for some reason Quote File exceeds the Maximum File limit Maximum File limit is 100000 File Array is Array bytes which seems odd because it does not even return the file size or name correctly. |