contra10 Posted January 3, 2009 Share Posted January 3, 2009 i can't seem to wrap my head around this, maybe im attempting to do this the wrong way but im creating a user specific upload for profile, and here part of my code <?php //print_r($_POST); if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $newimage = "file:///C|/wamp/www/images/" . $imagename; //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } ?> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?php $_SERVER["PHP_SELF"];?>"> <p><input type="file" name="image_file" size="20"></p> <p><input type="submit" value="Upload Image" name="action"></p> </form> <?php if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } ?> i placed my file images in *www* folder and nothing is going there at the same time how do i make the photo user specific, i passed on the user id to this upload page Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/ Share on other sites More sharing options...
l0ve2hat3 Posted January 3, 2009 Share Posted January 3, 2009 put this at the top of your code error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/#findComment-728701 Share on other sites More sharing options...
contra10 Posted January 3, 2009 Author Share Posted January 3, 2009 i get Notice: Undefined index: action in C:\wamp\www\photoupload\index.php on line 12 Notice: Undefined variable: error in C:\wamp\www\photoupload\index.php on line 49 Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/#findComment-728754 Share on other sites More sharing options...
Nitroware Posted January 3, 2009 Share Posted January 3, 2009 The first one is because (I think) $error is not defined as an array: <? $error=array(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/#findComment-728761 Share on other sites More sharing options...
contra10 Posted January 4, 2009 Author Share Posted January 4, 2009 i still get those errors, maybe i should do photo upload differently? Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/#findComment-729097 Share on other sites More sharing options...
premiso Posted January 4, 2009 Share Posted January 4, 2009 It really has nothing to do with why your script is not working, but here is how to fix those 2 issues: <?php //print_r($_POST); $error = ""; // set error to avoid notice's. if(isset($_POST['action'] && $_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $newimage = "file:///C|/wamp/www/images/" . $imagename; //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } ?> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?php $_SERVER["PHP_SELF"];?>"> <p><input type="file" name="image_file" size="20"></p> <p><input type="submit" value="Upload Image" name="action"></p> </form> <?php if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } ?> I will look at it closer to see why it does not work. It would be a ton easier and you might get more responses if you indented your code properly. Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/#findComment-729118 Share on other sites More sharing options...
contra10 Posted January 4, 2009 Author Share Posted January 4, 2009 ok thaks for the tip Quote Link to comment https://forums.phpfreaks.com/topic/139323-photo-uploads/#findComment-729131 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.