PHP - Probably Can't Be More Basic! Warning: Copy() [function.copy]: Filename Cannot
This was generated through phpFormGenerator, but I'm getting the following warning message when a file is not uploaded. I didn't set it as a required field.
"Warning: copy() [function.copy]: Filename cannot be empty ..." If it possible to skip this check since it's not supposed to be required to upload a file? I'm simply trying to make a contact form that emails basic information with the added option of attaching a file/picture. Code: [Select] <?php include("global.inc.php"); $errors=0; $error="The following errors occured while processing your form input.<ul>"; pt_register('POST','FullName'); pt_register('POST','Email'); pt_register('POST','Phone'); pt_register('POST','QuestionsorComments'); $QuestionsorComments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $QuestionsorComments);$AttachPictureforQuote=$HTTP_POST_FILES['AttachPictureforQuote']; pt_register('POST','Howdidyoufindus'); if($FullName=="" || $Email=="" ){ $errors=1; $error.="<li>You did not enter one or more of the required fields. Please go back and try again."; } if($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'])){ $error.="<li>The file, ".$HTTP_POST_FILES['AttachPictureforQuote']['name'].", was not uploaded!"; $errors=1; } if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){ $error.="<li>Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $image_part = date("h_i_s")."_".$HTTP_POST_FILES['AttachPictureforQuote']['name']; $image_list[4] = $image_part; copy($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'], "files/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); $message="Full Name: ".$FullName." Email: ".$Email." Phone: ".$Phone." Questions or Comments: ".$QuestionsorComments." Attach Picture for Quote: ".$where_form_is."files/".$image_list[4]." How did you find us: ".$Howdidyoufindus." "; $message = stripslashes($message); mail("webmaster@gmail.com","Form Submitted at your website",$message,"From: phpFormGenerator"); ?> <!-- This is the content of the Thank you page, be careful while changing it --> <h2>Thank you!</h2> <table width=50%> <tr><td>Full Name: </td><td> <?php echo $FullName; ?> </td></tr> <tr><td>Email: </td><td> <?php echo $Email; ?> </td></tr> <tr><td>Phone: </td><td> <?php echo $Phone; ?> </td></tr> <tr><td>Questions or Comments: </td><td> <?php echo $QuestionsorComments; ?> </td></tr> <tr><td>Attach Picture for Quote: </td><td> <?php echo $AttachPictureforQuote; ?> </td></tr> <tr><td>How did you find us: </td><td> <?php echo $Howdidyoufindus; ?> </td></tr> </table> <!-- Do not change anything below this line --> <?php } ?> Thanks for your time and any help you can provide! Similar TutorialsHi guys, I am wirting a script to upload an image file, but I get the error: copy() [function.copy]: Filename cannot be empty in Obviouly it has something to do with the copy() function - (copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) I think it is not copying from my temp folder or something. Can anyone help me out? Code is: Code: [Select] //IMAGE FILE $file_name = $_FILES['product_img']['name']; echo '<p>File Name:' . $file_name . '</p>'; //IMAGE UPLOAD // random 4 digit to add to file name $random_digit=rand(0000,9999); //combine random digit to file name to create new file name //use dot (.) to combile these two variables $new_image_name = $random_digit.$file_name; echo $new_image_name; //SET DESINATION FOLDER $path= "uploads/".$new_image_name; echo '<p>Path:' . $path . '</p>'; if($product_img !=none) { if(copy($HTTP_POST_FILES['product_img']['tmp_name'], $path)) { echo "Successful<BR/>"; echo "File Name :".$new_file_name."<BR/>"; echo "File Size :".$HTTP_POST_FILES['product_img']['size']."<BR/>"; echo "File Type :".$HTTP_POST_FILES['product_img']['type']."<BR/>"; } else { echo "Image upload Error<BR/>"; } } Any help would be greatly appreciated! Thanks Ok I am designing a php upload that will take a image file from a form and change the name of the file to the productnumber also recieved from the form. I had it working the otherday now it says Warning: copy() [function.copy]: open_basedir restriction in effect File() is not within the allowed path(s): (/home:/tmp:/usr) addpro.php on line 51. my files are attached.... note that $pnum is the product number gotten from my form and image is the image being uploaded gotten from the form also. The thing is it worked the other day but now it don't is it a change to the server ( I dont run the server) or did I mess up my code since then? I really need a code that will do this two time over once for a small image being put into a folder called small and once for a folder called large both images being uploaded and being changed to $pnum.ext so they will both be displayed when being called out by the product number. but I can work on that after I get this one working. line 51 is $copied = copy($_FILES['image']['tmp_name'], $newname); I came across the PHP clone method. Does this clone first level fields and methods or does it also do deep copying e.g. copying references to those fields. For example, a field may be an array. Does it make a copy of the actual array or does it refer to the same array position in memory, so if the original changes, then the copy's changes as well?
Hello freaks, I am currently creating a member system that will place a default handle image into a newly registered members file. I have used the mkdir function create the directory successfully based on the members ID, but I can't get the copy function to work. Code: Code: [Select] mkdir("memberFiles/$memberID", 0755); $old = 'images/defaultlogo.jpg'; $new = 'memberFiles/$memberID/logo.jpg'; copy($old, $new); Error Message: Warning: copy(memberFiles/$memberID/logo.jpg) [function.copy]: failed to open stream: No such file or directory Lastly, this folder is created to store members files. Hello everyone, so I made this script that creates directories via "a hack around" cPanel, on my own server, in order to create directories via my own software, but I also need to copy files from one directory into that newly created directory... Therein lies the problem... I created a script a few years ago that worked, but for the life of me I can't remember how I enabled myself to be able to use the copy function of php... Anybody know? hi i made my very first array, and its working great now i want to have another array wich does the same thing, but on another category, it shows gold silver and bronze logos, but now i want to give leaders of other categorys also those logos, but different ones so i thought i change from $array[$snipergameid][$x] = $sniperleaders[playerid]; (part of the code in a while loop) into $array2[$snipergameid][$x] = $sniperleaders[playerid]; (part of the code in a while loop) and i do the same for the result checker loops but that doesnt work so how do i copy an entire arrray, and give it another name to match it with the correct while loop checker? hey people i cant get copy() to work. im working on an online server and trying to copy a file into directories i just created. i read about fopen() having to be enabled if both source and destination files are urls, and fopen is enabled and both files are urls (and on the same server). the directories get created but the file doesnt get copied. the directories have permission 777. could it be that when i call the copy function the directories aren't yet available on the server? i am copying the file in the same code block as 'create folders', right after. any pointers? hey, can some one provide a code to help me copy a folder called contents with files in it to another folder called items cheers Hello, im new to php and I would appreciate help with this one.... Error code is Warning: copy() expects parameter 1 to be string, array given in /path/to/file/http.class.php on line 143 Error block Code: [Select] if (count($_FILES) > 0) { foreach ($_FILES as $name => $file) { if ($file['tmp_name']) { $newfile=dirname(__FILE__).'/../cache/'.$file['name']; $newfiles[]=$newfile; copy ($file['tmp_name'],$newfile); if ($file['tmp_name']) $this->post[$name]='@'.$newfile; } } } Line 143 Code: [Select] copy ($file['tmp_name'],$newfile); I have a DB with 10 fields Records are entered under a date There can be 1 to 30 records for a given date I need to copy all records of a given date with the 10 fields of each... Into the same DB only changing the original date to a new date Sounds easy, but so far I haven't been able to make it work. Any nudge in the right directiion would be much appreciated. So my hosting server does not allow fopen anymore, so I was wondering if anyone had an alternative to copying a file from a remote server via a URL to a local folder? Any alternatives is apprecited. Hello, I need help. I want to know how to copy a field value of a table from one database to other database using php. I have a field name "invites" in a table "members" in database "db1" and a field name "new_invites" in a table "new_members" in database "db2". I want to copy value of field "invites" to "new_invites". How to do that? Hi Guys, Basically, I have a long php script to calculate the nearest branch dependant on there postcode hence why $to = $branchemail at the end. It will send it to HQ if anything goes wrong as a safeguard. Here is a small piece of my php code: if (strlen($branchemail) == 0){ // Default Address if anything goes wrong $to = "hq@example.com"; } else { // The address of the branch to send to $to = $branchemail; } What I can't seem to do is also send the customer filling in the php form a copy of the email sent. The variable for the customers email is $email I have tried this and it doesn't seem to work either... // The address of the branch to send to $to = $branchemail; $to .= $email; } At the bottom of the script, there is this code to physically send the email. This also always sends a copy to hq aswell. echo "Thank you for contacting us, we have received your message and we aim to respond your very shortly."; mail($to, $subject, $body, $mailheader); // THIS LINE TO CC Email mail("hq@example.com", $subject, $body, $mailheader); } else { echo "There has been an error code 1. Please try again."; So basically I just can't get it to send a copy to the customer filling it in ($email) Any idea's because my mind has gone blank. Cheers, S Hi all I am trying to write a piece of code that copies files from a multiple selected form. Here's the form: Code: [Select] <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="image[]" multiple="multiple" /> <input name="submit" type="submit" value="submit"> </form> Here's my PHP code: Code: [Select] if(isset($_POST['submit'])) { $count=0; foreach($_FILES['image'] as $filename){ copy($_FILES['image']['tmp_name'], WEB_UPLOAD."/images/galleries/".$filename) or die("Error uploading image "); $count++; } } I get the message, Array to string conversion and no such directory found. Am I right in thinking I am sending the files as arrays? Many thanks for your help. I know this code works
INSERT INTO archive_table SELECT * FROM original_table WHERE id = 1But i want to also add the current date whenever i copy the data into a new table. Thanks in advance Hi I have a script Code: [Select] mkdir("myitems/images", 0777); chmod("myitems/images", 0777); if (!copy('downloads.zip', 'myitems/images/downloads.zip')) { echo "failed"; } when I run it, the folder is created and when checking folder permissions, it shows 777 but it fails on copying the file. if I manually create the folder "myitems/images/" and set it to 777, then when I run the script, the file is copied for some reason when I manually create the folder it works, but when PHP creates the folder, it fails on something any ideas? racking my brain trying to figure out why I have a survey that uses colors. At the moment someone takes the survey I need to capture the values that are in a table called "tbl_colors" and write them to each survey in "tbl_surveys" as a row. tbl_colors id, hex_color 1 FFF432 2 CC3399 3 DD3399 and so on to the number 12 tbl_survey id, timestamp, name, hex01, hex02, hex03, hex04, etc to hex12 I have written code that "works" but I know it is extremely redundant and overloaded and someone could probably do the same thing in less than 10 lines of code. So, I post it here so I can learn from my mistakes. // Make a MySQL Connection $query = "SELECT * FROM tbl_colors WHERE id = 1"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color1 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 2"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color2 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 3"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color3 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 4"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color4 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 5"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color5 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 6"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color6 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 7"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color7 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 8"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color8 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 9"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color9 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 10"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color10 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 11"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color11 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 12"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color12 = $row['hex_color']; //echo $color1.$color2.$color3.$color4.$color5.$color6.$color7.$color8.$color9.$color10.$color11.$color12; mysql_query("INSERT INTO tbl_surveys (hex01, hex02, hex03, hex04, hex05, hex06, hex07, hex08, hex09, hex10, hex11, hex12) VALUES ('$color1', '$color2', '$color2', '$color3', '$color4', '$color5', '$color6', '$color7', '$color8', '$color9', '$color10', '$color11', '$color12')"); How would I copy an array of selected files? I know how to list them using a 'for' loop, and how to separate them using a 'foreach' loop, but I am unable to get a checkbox array to copy to a destination folder. Help is appreciated. hey guys its me again. what i want is for me to be able to edit php using variables and post it as a new file. now to attchieve this i am simply copying the current template into the php file and telling it to grap what variables it needs. i have successfully done this with a .css file but when im doing it with a php file its erroring at <?php as the file is already in php. what i need to know is can i have the php file look at the <?php as just text to write to a file? my code is below Code: [Select] $dir = "../Header/"; $file = "" . $branchid . ".php"; $dir = "$dir"."$file"; touch($dir); $Handle = fopen($dir, 'w'); $Data = " <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php //We count the number of new messages the user has $nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['user_id'].'" and user1read="no") or (user2="'.$_SESSION['user_id'].'" and user2read="no")) and id2="1"')); //The number of new messages is in the variable $nb_new_pm $nb_new_pm = $nb_new_pm['nb_new_pm']; ?> <html xmlns="http://www.w3.org/1999/xhtml"> <style type="text/css"> /* Remove margins from the 'html' and 'body' tags, and ensure the page takes up full screen height */ html, body { margin:0; padding:0;} /* Set the position and dimensions of the background image. */ #page-background {position:fixed; top:0; left:0; width:100%; height:100%;} /* Specify the position and layering for the content that needs to appear in front of the background image. Must have a higher z-index value than the background image. Also add some padding to compensate for removing the margin from the 'html' and 'body' tags. */ #content {position:relative; z-index:1; padding:10px;} </style> <head> <title>Apollo - Data Management System</title> <!--Links--> <link rel="icon" type="image/ico" href="favicon.ico"></link> <link rel="stylesheet" media="all" type="text/css" href="/styles.css" /> </head> <body> <div id="Headerlogo"> <img src="/images/PaulKemp/PaulBanner.png" width="100%" alt="Smile"></div> <div class="wrapper1"> <div class="wrapper"> <div class="nav-wrapper"> <div class="nav"> <ul id="navigation"> <li class="active"> <a href="/Main/myaccount.php"> <span class="menu-left"></span> <span class="menu-mid">Main Menu</span> <span class="menu-right"></span> </a> </li> <li class=""> <a href="/PersonnelMessages/list_pm.php"> <span class="menu-left"></span> <span class="menu-mid"><b>Messages(<?php echo $nb_new_pm; ?> unread)</b></span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/PersonnelMessages/new_pm.php">New Personal Message</a> </li> </ul> <div class="btm-bg"></div> </div> </li> <?php if (checkMasterAdmin()) { ?> <li class=""> <a href="#"> <span class="menu-left"></span> <span class="menu-mid">Admin</span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/Admin/UploadServices.php">New KPI</a> </li> <li> <a href="/Admin/MonthReview.php">New Month Review</a> </li> <li> <a href="/Admin/CreateUser.php">New User</a> </li> <li> <a href="/Admin/EditUsers.php">Edit User</a> </li> <li> <a href="/Admin/HolidayRequests.php">Authorise Holidays</a> </li> <li> <a href="/Backup/BackupSite.php">Backup</a> </li> <li> <a href="/PersonnelMessages/CompanyAnnouncement.php">Company Announcements</a> </li> <li> <a href="/PersonnelMessages/DeleteAnnouncements.php">Delete Announcements</a> </li> </ul> <div class="btm-bg"></div> </div> </li> <?php } ?> <?php if (checkAdmin()) { ?> <li class=""> <a href="#"> <span class="menu-left"></span> <span class="menu-mid">Admin</span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/Admin/UploadServices.php">New KPI</a> </li> <li> <a href="/Admin//MonthReview.php">New Month Review</a> </li> <li> <a href="/Admin/CreateUser.php">New User</a> </li> <li> <a href="/Admin/EditUsers.php">Edit User</a> </li> <li> <a href="/Admin/HolidayRequests.php">Authorise Holidays</a> </li> <li> <a href="/Backup/BackupSite.php">Backup</a> </li> <li> <a href="/PersonnelMessages/CompanyAnnouncement.php">Company Announcements</a> </li> <li> <a href="/PersonnelMessages/DeleteAnnouncements.php">Delete Announcements</a> </li> </ul> <div class="btm-bg"></div> </div> </li> <?php } ?> <?php if (checkBranchOwner()) { ?> <li class=""> <a href="#"> <span class="menu-left"></span> <span class="menu-mid">Admin</span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/Admin/UploadServices.php">New KPI</a> </li> <li> <a href="/Admin//MonthReview.php">New Month Review</a> </li> <li> <a href="/Admin/CreateUser.php">New User</a> </li> <li> <a href="/Admin/EditUsers.php">Edit User</a> </li> <li> <a href="/Admin/HolidayRequests.php">Authorise Holidays</a> </li> <li> <a href="/Backup/BackupSite.php">Backup</a> </li> <li> <a href="/PersonnelMessages/CompanyAnnouncement.php">Company Announcements</a> </li> <li> <a href="/PersonnelMessages/DeleteAnnouncements.php">Delete Announcements</a> </li> </ul> <div class="btm-bg"></div> </div> </li> <?php } ?> <li class=""> <a href="#"> <span class="menu-left"></span> <span class="menu-mid">Staff</span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/Staff/ChangePassword.php">Change Password</a> </li> <li> <a href="/Staff/mysettings.php">Change Details</a> </li> <li> <a href="/Staff/HolidaysLeft.php">Holidays Left</a> </li> <li> <a href="/Staff/profile.php">My Profile</a> </li> <li> <a href="/Staff/MyServices.php">My Services</a> </li> <li> <a href="/Viewmonthreports.php">Month Review</a> </li> </ul> <div class="btm-bg"></div> </div> </li> <li class=""> <a href="#"> <span class="menu-left"></span> <span class="menu-mid">Referrers</span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/Referrers/Newreferrers.php">New Referrers</a> </li> <li> <a href="/Referrers/SendReferrers.php">Send Referrers</a> </li> </ul> <div class="btm-bg"></div> </div> </li> <li class=""> <a href="#"> <span class="menu-left"></span> <span class="menu-mid">Holidays</span> <span class="menu-right"></span> </a> <div class="sub"> <ul> <li> <a href="/Holidays/RequestHoliday.php">Book Off Holiday</a> </li> <?php if (checkAdmin()) { ?> <li> <a href="/Admin/HolidayAmendments.php">Amend Holidays</a> </li> <li> <a href="/Admin/CancelledHolidays.php">Show Cancelled Holidays</a> </li> </li> <li> <a href="/reports/holidayreports.php">holiday report</a> </li> <?php } ?> <?php if (checkMasterAdmin()) { ?> <li> <a href="/Admin/HolidayAmendments.php">Amend Holidays</a> </li> <li> <a href="/Admin/CancelledHolidays.php">Show Cancelled Holidays</a> </li> <li> <a href="/reports/holidayreports.php">holiday report</a> </li> <?php } ?> </ul> <div class="btm-bg"></div> </div> </li> <li class=""> <a href="/logout.php"> <span class="menu-left"></span> <span class="menu-mid">Logout</span> <span class="menu-right"></span> </a> </li> </ul> </div> </div> </div> </div> <br /> "; fwrite($Handle, $Data); $Data = "Bilbo Jones\n"; fwrite($Handle, $Data); print "Data Written"; fclose($Handle); I am trying from several hours to sort and issue but i donno what the problem.. this is the following code i am using mkdir("news_upload/$year/$month/$day",0777); touch("news_upload/$year/$month/$day/$title.php"); chmod("news_upload/$year/$month/$day/$title.php",0777); $template = "news_template.php"; $new = "news_upload/$year/$month/$day/$title.php"; copy($template,$new); I have created the directories and given the permission the made a new empty file.. i added permissions to the new made file.. but it didnt apply as i check it.. (PROBLEM) then i have a template designed with the name news_template.php wanted to copy this template to the new created file.. the file gets created.. but the new file is not copying the template file on itself.. have i done anything rong??? help please? |