Jump to content

co.ador

Members
  • Posts

    726
  • Joined

  • Last visited

    Never

Everything posted by co.ador

  1. MGA never mind it was inserting all this time even before the thing is I was using $id = SESSION['user_id']; and I needed $product_id = $_POST['product_id']; Sorry for the inconvenience. Thank you for your post.
  2. @MGA ok, i can see how you did directly. now, When i submitted the form it print "File is valid, and was successfully uploaded" but when I go to the inventory_images I don't find neither the orginal file name or the renamed one which would be 194.jpg which was the id created this time. I have the script set up to echo the $id variale after form has submitted but I don't see the file.
  3. mga I just put a snipet of the whole code but the $id is all the way in the code and it is echoing. I will try your suggestion.
  4. The Global $_FILE field value is <?php basename($_FILES['file']['name'] ?> the variable value is <?php $newname = $id . ".jpg" ?> The Field "file" is carry a value of a picture for instance penguin.jpg and then I want to replace that name for $id . ".jpg" to make a new name for the file and replace it for the id fo the product like 34.jpg. I am working on an upload file script so far is moving the file but with the original name and I trying to make a new and rename it to the id of the product the script is as below and so far is inserting the original name of the file in $uploaddir . basename($_FILES['file']['name'] instead I am looking for something like $uuploaddir . $newname which #newname is equal to $id. "jpg" <?php // $newname = $id . ".jpg"; $uploaddir = '/home3/ny/public_html/your/inventory_images/'; $uploadfile = $uploaddir . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "File was not uploaded\n"; } ?> Any suggestions? so far as I said the existing code is uploading but with the original name file.
  5. Guys thanks.. PMF thank you for the steps they help me I did all of them I declared and filter all the variables before validation and then process the image move_uploaded_ifle and the data field insert and worked much better. After the script check there is not error or Variable $errors is === 0 then I executed the move_uploaded script function. I realized too that the path was not being specified correctly I needed to specified from the root level. I just need to replace basename($_FILES['file']['name']) for $newname = $id.".jpg"; so that the name of the picture is equal to the id of the product. <?php if (0 === count($errors)){ // $newname = $id . ".jpg"; $uploaddir = '/home3/nyh/public_html/youryardsales/inventory_images/'; $uploadfile = $uploaddir . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } //rest of the code. ?>
  6. One comment, Guys I never saw a comment on whether it is ok to have a picture field in this case name="file" and the rest of the text files together in one form. so in case I wanted to bring that up, I have done a update picture form submit alone with text fields with two form one for the picture field alone and then another for the text fields. I just want to know if it is ok to go ahead and work with one form or not.
  7. dind't quite understand so I have to get isset() around them ok. my bad
  8. The only undefined variables I had were the ones that were not defined such as $user_pic which I took that from another file code by mistake and $product that was mispelled now the real problem lay down in the indexes undefined indexes. I still on step 3 to 4
  9. @teynon From worked I checked the site was having some issues with the connection, @PFMaBiSmAd thank you.
  10. What happened with the rest of the replies? they erased them? The list of instructions given by PFMaBiSmAd and the other last suggestions. I just came home ready to work on that...
  11. I have put the error_reporting script on top and there is an undefined index according to error_reporting function. it comes out as undefined after it goes through a function. <?php function error_for($name){ global $errors; if($errors[$name]){ return "<div class='form_error'>". $errors[$name]; ?> This is the function which will print the errors below each field on the test for validations to see if the fields are empty or not. the undefined index will display on the screen below each form field before being submitted and after submittion with the error reporting_script above. Didn't see any error concerning the move_uploaded_file() function or the folder inventory_images. Don't know if those undefined indexes are the ones causing the problem, eventhough the INSERT query is inserting the field values in the database but the file in Mr, Inventory_images.
  12. I thought about the permissions, thought I think I have done that. Yes there is a folder called inventory_images in the same folder where the file is. This is the result for inventory_images folder Permission for this folder are set to 0755
  13. I finally came into an editor and figure out what was happening. Ok I have some result on the debugging script you just gave me. Yes the field $_FILES['file']['name'] Can't be move, Basically the form is submitted but the picture field not... The quote above is what is printing in the browser. In other words is not getting inside the folder. This is the script I am using to upload the file. <?php if (0 === count($errors)){ if (!$_FILES['file']['tmp_name']) { $error_msg = '<font color="#FF0000">ERROR: Please browse for an image before you press submit.</font>'; } else { $maxfilesize = 501200; // 51200 bytes equals 50kb if($_FILES['file']['size'] > $maxfilesize ) { $error_msg = '<font color="#FF0000">ERROR: Your image was too large, please try again.</font>'; unlink($_FILES['file']['tmp_name']); } else if (!preg_match("/\.(gif|jpg|png)$/i", $_FILES['file']['name'] ) ) { $error_msg = '<font color="#FF0000">ERROR: Your image was not one of the accepted formats, please try again.</font>'; unlink($_FILES['file']['tmp_name']); } else { $newname = $id . ".jpg"; // $place_file = move_uploaded_file( $_FILES['file']['tmp_name'], "inventory_images/$newname"); if(!move_uploaded_file( $_FILES['file']['tmp_name'], "inventory_images/$newname"){print "Cannot move {$_FILES['file']['name']}"; // Check to make sure the move result is true before continuing if ($place_file != true) { echo "ERROR: File not uploaded. Try again."; } } ?>[code] If there is not error the script above is set to upload or move_upload to the folder images_inventories. I am looking to name the picture or file to the user_id that's why I have tried to re-name it to [code]<?php $newname = $id . ".jpg" ?>
  14. i have placed this <?php if($place_file != true){ print("Cannot move {$_FILES['file']['name'])}"; $success_msg = '<font color="#009900">Your image has been updated, it may take a few minutes for the changes to show... please be patient.</font>';?> there is a parse error I don't have editor for blind people here lol I am a work Don't see a T_VARIABLE error here.
  15. The id is a is equal to the Variable session of the User id <?php $id = $_SESSION['user_id'];?> i just echo it and it is printing the id, so it means the $id is not empty, Also when I go to the product it will show or better said dispay a empty picture but with the name of the id of the product, Which means the id it's inserting but there is not picture plus it is not in the inventory_images.
  16. I have to give you the pro, This time doesn't present the message but when i go inside the invertory_images i don't see the image id= in this case is 180.jpg i don't see the image in there. Even though it is not presenting any error, I guess that what was happening before, any ideas?
  17. The code belows will present an error if there is not image in t he field, else it will go ahead change the name of <?php $_FILES['file']['tmp_name'], ?> to <?php $newname = $id . ".jpg"; ?> then inside the else if $place_file is not true then it will echo file not uploaded and that's the error i am getting now don't have any idea... <?php if (!$_FILES['file']['tmp_name']) { $error_msg = '<font color="#FF0000">ERROR: Please browse for an image before you press submit.</font>'; } else { $newname = $id . ".jpg"; $place_file = move_uploaded_file( $_FILES['file']['tmp_name'], "inventory_images/$nawname"); $success_msg = '<font color="#009900">Your image has been updated, it may take a few minutes for the changes to show... please be patient.</font>'; // Check to make sure the move result is true before continuing if ($place_file != true) { echo "ERROR: File not uploaded. Try again."; unlink ($_FILES['file']['tmp_name']); // Remove the uploaded file from the PHP temp folder } } ?>
  18. The condition below will execute if the form field has a file. as it is set up right now it throws an error saying that there is not such directory to insert the file which would be $id, the directory images exist but not the $id I was wondering if I need to c reate it first before inserting it? <?php else { $newname = $id.".jpg"; $place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "images/$id/".$newname); $success_msg = '<font color="#009900">Your image has been updated, it may take a few minutes for the changes to show... please be patient.</font>'; } be patient.</font>'; ?> This is the error when it try to insert the image if after it validates the field and test is not empty. Thanks
  19. Thank you dcro it works and it is even posting a message with the error for instant though it is failing to do so for the image I have to check that. <label class="ItemName" for="name">Item Name:</label> <input type="text" name="name" value="<?php echo $_POST['name']; ?>" /> <?php echo error_for('name'); ?> <label for="Price">Price:</label> <input type="text" name="price" value"price" /> <?php echo error_for('price');?> <label for="Details">Details:</label> <textarea name="details" cols="25" rows="6" value="<?php echo h($_POST['details']);?>"></textarea> <?php echo error_for('details');?> ?>
  20. Need a little help here guys I have come up with the following script for validating the fields before being submitted but still it is submitting the forms and overlooking this script. The test is not being executed. help. <?php if($_FILES['file']['error'] !== UPLOAD_ERR_OK || $_FILES['file']['size'] == 0) { $erros['image'] = "Please enter a image.";} //Check if item name is no-blank. if ( isset($_POST['name']) && $_POST['name'] === 0 ){ $errors['name'] = "Please enter Item name."; } if ( isset($_POST['price']) && $_POST['price'] === 0 ){ $errors['price'] = "Please enter Item price."; } if ( isset($_POST['details']) && $_POST['details'] === 0 ){ $errors['details'] = "Please enter details here."; } if ( isset($_POST['category_id']) && $_POST['category_id'] === 0 ){ $errors['category_id'] = "Please enter category.."; } if ( isset($_POST['city']) && $_POST['city'] === 0 ){ $errors['city'] = "Please enter city."; } if ( isset($_POST['state']) && $_POST['state'] === 0 ){ $errors['state'] = "Please enter state."; } if ( isset($_POST['zipcode']) && $_POST['zipcode'] === 0 ){ $errors['zipcode'] = "Please enter zipcode."; } ?>
  21. I use this check inside the request method if statement? like <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_FILES['image']['error'] !== UPLOAD_ERR_OK || $_FILES['image']['size'] == 0) { //Something went wrong } //Rest of the validation input fields. } ?>
  22. This is what I have come up with $errors is an array and I put the error message next to it just like suggested. The only thing I am not sure is about the GLOBAL $_FILES here <?phpif($_SERVER['REQUEST_METHOD'] == 'POST' || 'FILES'){ ?> The action of the form is POST but the image input field type is file I don't know if I just should reference it as POST or FILES thanks. <?php if($_SERVER['REQUEST_METHOD'] == 'POST' || 'FILES'){ if( 0 === preg_match ("/\S+/", $_FILES['image'])){ $errorMsg['file']= "please insert a picture." } if( 0 === preg_match ("/\S+/", $_POST['file'])){ $errorMsg['name']= "please Insert Item Name." } if( 0 === preg_match ("/\S+/", $_POST['price'])){ $errorMsg['price']= "please enter Item price ." } if( 0 === preg_match ("/\S+/", $_POST['details'])){ $errorMsg['details']= "please enter Item Details." } if( 0 === preg_match ("/\S+/", $_POST['city'])){ $errorMsg['city']= "please enter city." } if( 0 === preg_match ("/\S+/", $_POST['state'])){ $errorMsg['state']= "please enter state." } if( 0 === preg_match ("/\S+/", $_POST['zipcode'])){ $errorMsg['zipcode']= "please insert a picture." } } ?>
  23. i have a question does the order of the variable definition and the variable in the if else statement validation approach does necessarily have to be in the same order as the fields names in the form? Just like INSERT queries require a certain order. 1- And yes I am missing some field in validation I make sure all fields are validated. thanks
×
×
  • 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.