divinedesigns1 Posted August 5, 2012 Share Posted August 5, 2012 hey guys, im having this problem i keep getting this error ( ! ) Notice: Undefined index: photo in C:\wamp\www\Newshyt\upload.php on line 27 but the index: photo is actually define in the form, but yet im having that error this is the code im now starting <?phpif(isset($_SESSION['uid'])){ echo '<h3>Upload Some Photos' . '</h3><br/><br/>'; ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="photo" value="Browse" /> <input type="submit" name="submit" value="upload" /> </form> <?php if(isset($_GET['album_id'], $_POST['submit'])){ $id = $_GET['album_id']; $upload = $_POST['photo']; if(empty($upload)){ echo 'bad'; }else{ echo 'good'; } }}else{ echo 'your a suckabutt';}?> as you can see in the form i have define the name of that input field to photo, and in the php script i point the variable to photo also, so why am i getting this error? Link to comment Share on other sites More sharing options...
divinedesigns1 Posted August 5, 2012 Author Share Posted August 5, 2012 problem solve, i was putting post instead of file Link to comment Share on other sites More sharing options...
kanchatchai Posted August 6, 2012 Share Posted August 6, 2012 use upload function inhttp://w3schools.invisionzone.com/index.php?showtopic=44522&view=findpost&p=247752and change $upload = $_POST['photo']; to $upload = upload('photo'); Link to comment Share on other sites More sharing options...
divinedesigns1 Posted August 6, 2012 Author Share Posted August 6, 2012 use upload function inhttp://w3schools.inv...ndpost&p=247752and change $upload = $_POST['photo']; to $upload = upload('photo'); you dont have to use a upload function to get it to work, i use the normal file function and it worked Link to comment Share on other sites More sharing options...
kanchatchai Posted August 6, 2012 Share Posted August 6, 2012 (edited) have move_uploaded_file function in it.easy to usefunction.php <?PHPfunction upload($file){ if(!file_exists(uploadfolder)) createfolder(uploadfolder); $allowedExts=explode(",",upload_allowfiletype); $filetype = explode(".", $_FILES[$file]["name"]); $filetype = end($filetype); if ( ( $_FILES[$file]["type"] == "image/gif" || $_FILES[$file]["type"] == "image/jpeg" || $_FILES[$file]["type"] == "image/pjpeg" ) && $_FILES[$file]["size"] < (allowfilesize*1024*1024) && in_array($filetype, $allowedExts) ) { if ($_FILES[$file]["error"] > 0) { echo "Return Code: " . $_FILES[$file]["error"] . "<br />"; return 'error: '.$_FILES[$file]["error"]; } else { echo "Upload: " . $_FILES[$file]["name"] . "<br />"; echo "Type: " . $_FILES[$file]["type"] . "<br />"; echo "Size: " . ($_FILES[$file]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES[$file]["tmp_name"] . "<br />"; } if (file_exists(uploadfolder."/" . $_FILES[$file]["name"])) { echo '<span style=" color:#00F;"> '.$_FILES[$file]["name"].'</span>' . '<span style=" color:#F00;">Already exists. </span>'; return 'error: File Already exists'; } else { if (rename_on_upload==TRUE) { //$filenewcon = strstr($_FILES[$file]["tmp_name"],'.'); $now = date("Ymd"); //date("Dgis"); $passw = rand()*7; $random_file_name=$now."-".$passw; //$random_file_name="$now$passw$filenewcon"; move_uploaded_file( $_FILES[$file]["tmp_name"],uploadfolder.'/'.$random_file_name.'.'.$filetype); echo '<span style=" color:#00F;">Stored in: ' .uploadfolder.'/'. $random_file_name.'.'.$filetype.'</span><br/><br/>'; return $random_file_name.'.'.$filetype; } else { //---------------------------------------------------------------------------------------------------- move_uploaded_file($_FILES[$file]["tmp_name"],uploadfolder.'/'.$_FILES[$file]["name"]); //echo "Stored in: " .uploadfolder.'/'. $_FILES[$file]["name"]."<br/><br/>"; echo '<span style=" color:#00F;">Stored in: <a href="'.uploadfolder.'">' .uploadfolder.'</a>'.$_FILES[$file]["name"].'</span>'; return $_FILES[$file]["name"]; } } } else { echo '<div style=" color:#F00;">Invalid file</div>'; return 'error: Invalid file'; }} function createfolder($foldername){//$foldername='FolderName';if(!file_exists($foldername)){ $flgCreate = mkdir($foldername,"0777"); if($flgCreate) { echo 'Folder <a href="'.$foldername.'">$foldername</a> Created.'; } else { echo 'Folder <a href="'.$foldername.'">$foldername</a> Not Create.<br/> Please Create Folder '.$foldername.' and Cmod to 777 By Your Self'; }}else{ // echo 'Folder <a href="'.$foldername.'">$foldername</a> Already Created';}}?> need config define('rename_on_upload',TRUE);//Auto Rename While Upload File To Serverdefine('uploadfolder','upload/');define('allowfilesize','2000000');define('upload_allowfiletype','gif,png,jpg,jpeg,doc,docx,xls,xlsx,ppt,pptx,jpg'); Edited August 6, 2012 by kanchatchai Link to comment Share on other sites More sharing options...
divinedesigns1 Posted August 6, 2012 Author Share Posted August 6, 2012 have move_uploaded_file function in it.easy to usefunction.php<?PHPfunction upload($file){ if(!file_exists(uploadfolder)) createfolder(uploadfolder); $allowedExts=explode(",",upload_allowfiletype); $filetype = explode(".", $_FILES[$file]["name"]); $filetype = end($filetype); if ( ( $_FILES[$file]["type"] == "image/gif" || $_FILES[$file]["type"] == "image/jpeg" || $_FILES[$file]["type"] == "image/pjpeg" ) && $_FILES[$file]["size"] < (allowfilesize*1024*1024) && in_array($filetype, $allowedExts) ) { if ($_FILES[$file]["error"] > 0) { echo "Return Code: " . $_FILES[$file]["error"] . "<br />"; return 'error: '.$_FILES[$file]["error"]; } else { echo "Upload: " . $_FILES[$file]["name"] . "<br />"; echo "Type: " . $_FILES[$file]["type"] . "<br />"; echo "Size: " . ($_FILES[$file]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES[$file]["tmp_name"] . "<br />"; } if (file_exists(uploadfolder."/" . $_FILES[$file]["name"])) { echo '<span style=" color:#00F;"> '.$_FILES[$file]["name"].'</span>' . '<span style=" color:#F00;">Already exists. </span>'; return 'error: File Already exists'; } else { if (rename_on_upload==TRUE) { //$filenewcon = strstr($_FILES[$file]["tmp_name"],'.'); $now = date("Ymd"); //date("Dgis"); $passw = rand()*7; $random_file_name=$now."-".$passw; //$random_file_name="$now$passw$filenewcon"; move_uploaded_file( $_FILES[$file]["tmp_name"],uploadfolder.'/'.$random_file_name.'.'.$filetype); echo '<span style=" color:#00F;">Stored in: ' .uploadfolder.'/'. $random_file_name.'.'.$filetype.'</span><br/><br/>'; return $random_file_name.'.'.$filetype; } else { //---------------------------------------------------------------------------------------------------- move_uploaded_file($_FILES[$file]["tmp_name"],uploadfolder.'/'.$_FILES[$file]["name"]); //echo "Stored in: " .uploadfolder.'/'. $_FILES[$file]["name"]."<br/><br/>"; echo '<span style=" color:#00F;">Stored in: <a href="'.uploadfolder.'">' .uploadfolder.'</a>'.$_FILES[$file]["name"].'</span>'; return $_FILES[$file]["name"]; } } } else { echo '<div style=" color:#F00;">Invalid file</div>'; return 'error: Invalid file'; }} function createfolder($foldername){//$foldername='FolderName';if(!file_exists($foldername)){ $flgCreate = mkdir($foldername,"0777"); if($flgCreate) { echo 'Folder <a href="'.$foldername.'">$foldername</a> Created.'; } else { echo 'Folder <a href="'.$foldername.'">$foldername</a> Not Create.<br/> Please Create Folder '.$foldername.' and Cmod to 777 By Your Self'; }}else{ // echo 'Folder <a href="'.$foldername.'">$foldername</a> Already Created';}}?> need config define('rename_on_upload',TRUE);//Auto Rename While Upload File To Serverdefine('uploadfolder','upload/');define('allowfilesize','2000000');define('upload_allowfiletype','gif,png,jpg,jpeg,doc,docx,xls,xlsx,ppt,pptx,jpg'); excuse me, the last time i spoke to you, i told you NOT to give me no script, kindly respect that and stop doing so, im not here to feed off of anyone by taking whatever script they give me and use it. so stop Link to comment Share on other sites More sharing options...
kanchatchai Posted August 6, 2012 Share Posted August 6, 2012 sory sory. Link to comment Share on other sites More sharing options...
kanchatchai Posted August 6, 2012 Share Posted August 6, 2012 (edited) you may change$_POST['photo']to$_FILES['photo']['name'] Edited August 6, 2012 by kanchatchai Link to comment Share on other sites More sharing options...
boen_robot Posted August 6, 2012 Share Posted August 6, 2012 you may change$_POST['photo']to$_FILES['photo']['name']Which is exactly what he already did (see second post in this topic) Link to comment Share on other sites More sharing options...
divinedesigns1 Posted August 6, 2012 Author Share Posted August 6, 2012 Which is exactly what he already did (see second post in this topic)oo just to update you, now i just need to create the thumbnail and woot woot that script can be kicked to the side and i can move onto the other one Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now