pixeltrace Posted July 26, 2007 Share Posted July 26, 2007 hi, i need help, i have a form that submits text information and image file but currently i am having errors or problem with the file upload codes that i have below is the code of my form <form action="brands/addbrands.php" method="post" enctype="multipart/form-data"> <table width="515" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="1" /></td> </tr> <tr> <td colspan="3" bgcolor="#999999" class="text2">BRAND INFORMATION</td> </tr> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td width="137" align="right" valign="top" class="text6">brand name : </td> <td> </td> <td class="text7"><input name="brand_name" type="text" size="40"></td> </tr> <tr> <td align="right" valign="top" class="text6">letter : </td> <td width="7"> </td> <td width="363"><span class="text6"> <select name="b_letter"> <option value="">by letter</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> <option value="E">E</option> <option value="F">F</option> <option value="G">G</option> <option value="H">H</option> <option value="I">I</option> <option value="J">J</option> <option value="K">K</option> <option value="L">L</option> <option value="M">M</option> <option value="N">N</option> <option value="O">P</option> <option value="Q">Q</option> <option value="R">R</option> <option value="S">S</option> <option value="T">T</option> <option value="U">U</option> <option value="V">V</option> <option value="W">W</option> <option value="X">X</option> <option value="Y">Y</option> <option value="Z">Z</option> </select> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">details: </td> <td width="7"> </td> <td><textarea name="brand_details" cols="50" rows="5"></textarea></td> </tr> <tr> <td align="right" valign="top" class="text6">URL : </td> <td width="7"> </td> <td width="363"><span class="text7"> <input name="brand_url" type="text" size="40" /> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">logo : </td> <td> </td> <td><input type="file" name="brand_logo" class="button1" /></td> </tr> <tr> <td align="right" valign="top" class="text6"> </td> <td> </td> <td class="text6">upload jpg or gif files only (max size 100K) </td> </tr> <tr> <td rowspan="2"> </td> <td rowspan="2"> </td> <td><input type="submit" name="Submit" value="save" /> <input type="hidden" name="username" value="<? echo "$username"; ?>"> <input type=hidden value=http://www. name=redirect> </td> </tr> <tr> <td> </td> </tr> </table> </form> and below is the code for my addbrands.php <? session_start(); if (session_is_registered("username")){ }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } include '../db_connect.php'; $brand_name = $_POST['brand_name']; $b_letter = $_POST['b_letter']; $brand_details = $_POST['brand_details']; $brand_url = $_POST['brand_url']; $brand_logo = $_POST['brand_logo']; $date_create = ('Y-m-d'); $username = $_POST['username']; //set this to the directory where resume files will be uploaded //directory path $uploaddir = '../ideas-people/engsoon/images/brandlogo/'; //get the dirrectory to send file to and the file name $uploadfile = $uploaddir . basename($_FILES['brand_logo']['brand_name']); // get the current file information. $file=$uploadfile; //get the . and file exstention. $ext = substr($file, -4); //convert varable to the uplaoded directory the new id and extention. $uploadfile=$uploaddir.$appid.$ext; //rename the file to the new one. @rename($file,$uploadfile); // if all the conditions are correct send the file to the directory. if(move_uploaded_file($_FILES['brand_logo']['tmp_name'], $uploadfile)) { $brand_name = stripslashes($brand_name); $b_letter = stripslashes($b_letter); $brand_details = stripslashes($brand_details); $brand_url = stripslashes($brand_url); $$date_create = stripslashes($$date_create); $brand_logo = stripslashes($brand_logo); $sql = mysql_query("INSERT INTO engsoon_brands (brand_name, b_letter, brand_details, brand_url, date_created, brand_logo ) VALUES('$brand_name', '$b_letter', '$brand_details', '$brand_url', '$date_created', '$uploadfile')") or die (mysql_error()); if(!$sql){ echo '<script language=javascript> alert("Error adding brand");top.location = "../brandsmngr.php?id=1&username='.$username.'";</script>'; exit(); } else { $bid = mysql_insert_id(); echo '<script language=javascript> alert("new brand has been added!");top.location = "../brandsmngr.php?id=2&username='.$username.'";</script>'; } } else{ echo '<script language=javascript> alert("error uploading image, please try again");history.back() = "brandsmngr.php?id=1&username='.$username.'";</script>'; } ?> this is the error message i am getting Warning: move_uploaded_file(../ideas-people/engsoon/images/brandlogo/ogo/) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/brennan/public_html/ideas-people/engsoon/admean/brands/addbrands.php on line 33 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpRmad0S' to '../ideas-people/engsoon/images/brandlogo/ogo/' in /home/brennan/public_html/ideas-people/engsoon/admean/brands/addbrands.php on line 33 i have set the attributes of that folder already and is located at this exact directory /public_html/ideas-people/engsoon/images/brandlogo/ i cannot determine what was the problem hope you could help me fix the code thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/ Share on other sites More sharing options...
dewey_witt Posted July 26, 2007 Share Posted July 26, 2007 http://www.phpfreaks.com/quickcode/Basic-FTP-File-upload-with-form/622.php Check this out maybe it'll help. Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-308353 Share on other sites More sharing options...
pixeltrace Posted July 26, 2007 Author Share Posted July 26, 2007 hi, any luck on this one? the link is meant for ftp file upload. hope someone could help me on this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-308409 Share on other sites More sharing options...
teng84 Posted July 26, 2007 Share Posted July 26, 2007 the path is the error echo this $uploadfile then paste the result to see the path Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-308411 Share on other sites More sharing options...
pixeltrace Posted July 27, 2007 Author Share Posted July 27, 2007 hi, i tried changing the uploadpath already but i am still getting some errors this is the error i am getting Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/images/brandlogo/ogo/) is not within the allowed path(s): (/home/brennan:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/brennan/public_html/ideas-people/engsoon/admean/brands/addbrands.php on line 34 i print the $uploadfile already and this is what i get /images/brandlogo/ogo/ where does the "ogo" come from, since the upload path i used is "images/brandlogo/" below is my current code <? session_start(); if (session_is_registered("username")){ }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } include '../db_connect.php'; $brand_name = $_POST['brand_name']; $b_letter = $_POST['b_letter']; $brand_details = $_POST['brand_details']; $brand_url = $_POST['brand_url']; $brand_logo = $_POST['brand_logo']; $date_create = ('Y-m-d'); $username = $_POST['username']; //set this to the directory where resume files will be uploaded //directory path $uploaddir = '/images/brandlogo/'; //get the dirrectory to send file to and the file name $uploadfile = $uploaddir . basename($_FILES['brand_logo']['brand_name']); // get the current file information. $file=$uploadfile; //get the . and file exstention. $ext = substr($file, -4); //convert varable to the uplaoded directory the new id and extention. $uploadfile=$uploaddir.$appid.$ext; //rename the file to the new one. @rename($file,$uploadfile); // if all the conditions are correct send the file to the directory. print_r($uploadfile); if(move_uploaded_file($_FILES['brand_logo']['tmp_name'], $uploadfile)) { $brand_name = stripslashes($brand_name); $b_letter = stripslashes($b_letter); $brand_details = stripslashes($brand_details); $brand_url = stripslashes($brand_url); $$date_create = stripslashes($$date_create); $brand_logo = stripslashes($brand_logo); $sql = mysql_query("INSERT INTO engsoon_brands (brand_name, b_letter, brand_details, brand_url, date_created, brand_logo ) VALUES('$brand_name', '$b_letter', '$brand_details', '$brand_url', '$date_created', '$uploadfile')") or die (mysql_error()); if(!$sql){ echo '<script language=javascript> alert("Error adding brand");top.location = "../brandsmngr.php?id=1&username='.$username.'";</script>'; exit(); } else { $bid = mysql_insert_id(); echo '<script language=javascript> alert("new brand has been added!");top.location = "../brandsmngr.php?id=2&username='.$username.'";</script>'; } } else{ echo '<script language=javascript> alert("error uploading image, please try again");history.back() = "brandsmngr.php?id=1&username='.$username.'";</script>'; } ?> hope you could help me with this. thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-308905 Share on other sites More sharing options...
pixeltrace Posted July 27, 2007 Author Share Posted July 27, 2007 hi any help on this please? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-308980 Share on other sites More sharing options...
pixeltrace Posted July 27, 2007 Author Share Posted July 27, 2007 hi, i tried another code but its giving me another error Warning: copy() [function.copy]: open_basedir restriction in effect. File(/public_html/ideas-people/engsoon/images/brandlogo/2ca0.jpg) is not within the allowed path(s): (/home/brennan:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/brennan/public_html/ideas-people/engsoon/admean/brands/addbrands.php on line 40 Warning: copy(/public_html/ideas-people/engsoon/images/brandlogo/2ca0.jpg) [function.copy]: failed to open stream: Operation not permitted in /home/brennan/public_html/ideas-people/engsoon/admean/brands/addbrands.php on line 40 upload failed! and this is my current code for my form <form action="brands/addbrands.php" method="post" enctype="multipart/form-data"> <table width="515" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="1" /></td> </tr> <tr> <td colspan="3" bgcolor="#999999" class="text2">BRAND INFORMATION</td> </tr> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td width="137" align="right" valign="top" class="text6">brand name : </td> <td> </td> <td class="text7"><input name="brand_name" type="text" size="40"></td> </tr> <tr> <td align="right" valign="top" class="text6">letter : </td> <td width="7"> </td> <td width="363"><span class="text6"> <select name="b_letter"> <option value="">by letter</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> <option value="E">E</option> <option value="F">F</option> <option value="G">G</option> <option value="H">H</option> <option value="I">I</option> <option value="J">J</option> <option value="K">K</option> <option value="L">L</option> <option value="M">M</option> <option value="N">N</option> <option value="O">P</option> <option value="Q">Q</option> <option value="R">R</option> <option value="S">S</option> <option value="T">T</option> <option value="U">U</option> <option value="V">V</option> <option value="W">W</option> <option value="X">X</option> <option value="Y">Y</option> <option value="Z">Z</option> </select> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">details: </td> <td width="7"> </td> <td><textarea name="brand_details" cols="50" rows="5"></textarea></td> </tr> <tr> <td align="right" valign="top" class="text6">URL : </td> <td width="7"> </td> <td width="363"><span class="text7"> <input name="brand_url" type="text" size="40" /> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">logo : </td> <td> </td> <td><input type="file" name="userfile" class="button1" /></td> </tr> <tr> <td align="right" valign="top" class="text6"> </td> <td> </td> <td class="text6">upload jpg or gif files only (max size 100K) </td> </tr> <tr> <td rowspan="2"> </td> <td rowspan="2"> </td> <td><input type="submit" name="Submit" value="save" /> <input type="hidden" name="username" value="<? echo "$username"; ?>"> <input type=hidden value=http://www. name=redirect> </td> </tr> <tr> <td> </td> </tr> </table> </form> and this is the current code in my addbrands.php <? session_start(); if (session_is_registered("username")){ }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } include '../db_connect.php'; $brand_name = $_POST['brand_name']; $b_letter = $_POST['b_letter']; $brand_details = $_POST['brand_details']; $brand_url = $_POST['brand_url']; $brand_logo = $_POST['brand_logo']; $date_created = date('Y-m-d'); $username = $_POST['username']; $path = "/public_html/ideas-people/engsoon/images/brandlogo/"; $max_size = 200000; if (!isset($HTTP_POST_FILES['userfile'])) exit; if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>"; exit; } if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>"; exit; } $res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path . $HTTP_POST_FILES['userfile']['name']); if (!$res) { echo "upload failed!<br>"; exit; } else { echo "upload sucessful<br>"; } echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>"; echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>"; echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>"; } else { echo "Wrong file type<br>"; exit; } } $my_file = $HTTP_POST_FILES['userfile']['name']; $brand_name = stripslashes($brand_name); $b_letter = stripslashes($b_letter); $brand_details = stripslashes($brand_details); $brand_url = stripslashes($brand_url); $$date_create = stripslashes($$date_create); $brand_logo = stripslashes($brand_logo); $sql = mysql_query("INSERT INTO engsoon_brands (brand_name, b_letter, brand_details, brand_url, date_created, brand_logo ) VALUES('$brand_name', '$b_letter', '$brand_details', '$brand_url', '$date_created', '$userfile')") or die (mysql_error()); if(!$sql){ echo '<script language=javascript> alert("Error adding brand");top.location = "../brandsmngr.php?id=1&username='.$username.'";</script>'; exit(); } else { $bid = mysql_insert_id(); echo '<script language=javascript> alert("new brand has been added!");top.location = "../brandsmngr.php?id=2&username='.$username.'";</script>'; } ?> hope you could help me with this. thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-309000 Share on other sites More sharing options...
pixeltrace Posted July 28, 2007 Author Share Posted July 28, 2007 hi, from my understanding, this is already a settings that needs to be done in the php.ini is there any php code that you can run so that when you execute the file upload form it will either enable or disable the open_basedir in the php.ini? hope you could help me with this. thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-309428 Share on other sites More sharing options...
pixeltrace Posted July 28, 2007 Author Share Posted July 28, 2007 hi, any help on this one please? i was able to located the allowed folder already but when i run submit my form with the file upload. its telling me that the adding of the brand item is successful however when i go to the folder where the images were supposed to be save is empty. below is my codes <? session_start(); if (session_is_registered("username")){ }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } include 'db_connect.php'; $brand_name = $_POST['brand_name']; $brand_details = $_POST['brand_details']; $brand_url = $_POST['brand_url']; $userfile = $_POST['userfile']; $date_created = date('Y-m-d'); $username = $_POST['username']; $photo = $_POST['photo']; if ($_FILES["photo"]["error"] > 0) { echo "Error: " . $_FILES["photo"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["photo"]["name"] . "<br />"; echo "Type: " . $_FILES["photo"]["type"] . "<br />"; echo "Size: " . ($_FILES["photo"]["size"] / 2000) . " Kb<br />"; echo "Stored in: " . $_FILES["photo"]["tmp_name"]; } if ($_FILES["photo"]["error"] > 0) { echo "Return Code: " . $_FILES["photo"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["photo"]["name"] . "<br />"; echo "Type: " . $_FILES["photo"]["type"] . "<br />"; echo "Size: " . ($_FILES["photo"]["size"] / 2000) . " Kb<br />"; echo "Temp file: " . $_FILES["photo"]["tmp_name"] . "<br />"; if (file_exists("tmp/brandlogo/" . $_FILES["photo"]["name"])) { echo $_FILES["photo"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["photo"]["tmp_name"], "tmp/brandlogo/" . $_FILES["file"]["name"]); echo "Stored in: " . "tmp/brandlogo/" . $_FILES["photo"]["name"]; } } //brand verification $sql_brand_name_check = mysql_query("SELECT brand_name FROM engsoon_brands WHERE brand_name='$brand_name'"); $brand_name_check = mysql_num_rows($sql_brand_name_check); if($brand_name_check > 0){ echo '<script language=javascript> alert("brand name already exist!");top.location = "brandsmngr.php?id=1";</script>'; unset($brand_name); exit(); } $brand_name = stripslashes($brand_name); $b_letter = stripslashes($b_letter); $brand_details = stripslashes($brand_details); $brand_url = stripslashes($brand_url); $$date_create = stripslashes($$date_create); $sql = mysql_query("INSERT INTO engsoon_brands (brand_name, brand_details, brand_url, date_created, brand_logo ) VALUES('$brand_name', '$brand_details', '$brand_url', '$date_created', '$photo')") or die (mysql_error()); if(!$sql){ echo '<script language=javascript> alert("Error adding brand");top.location = "brandsmngr.php?id=1";</script>'; exit(); } else { $bid = mysql_insert_id(); echo '<script language=javascript> alert("new brand has been added!");top.location = "brandsmngr.php?id=2";</script>'; } ?> hope you could help me with this. thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-309485 Share on other sites More sharing options...
AdRock Posted July 28, 2007 Share Posted July 28, 2007 Maybe be a silly question but does a folder exist on the server where you want to upload the file and has permissions been set? I only ask as I accidentally deleted a folder on my server and I had similar problems Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-309500 Share on other sites More sharing options...
pixeltrace Posted July 28, 2007 Author Share Posted July 28, 2007 hi, i was able to solve it already. i used the codes from this page http://www.phpfreaks.com/quickcode/Basic-FTP-File-upload-with-form/622.php it really works. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/61887-solved-need-help-in-file-upload/#findComment-309549 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.