techiefreak05 Posted January 3, 2007 Share Posted January 3, 2007 Hi, I have an image upload script that is having some issues ... It says its uploads just fine, but it doesn't, can anybody see why?[code]<?php if($_POST["action"] == "-Upload-") { unset($picfile_name); //Prevent from uploading Again! :P if(! isset($_FILES['image_file'])) { $error = "An image was not found."; } $max_space = 524288; //.5 mg $files = array("image/gif", // Gif "image/jpeg", // jpe jpeg jpg "png", // PNG ); $picfile_name = $_FILES['image_file']['name']; $picfile_type = $_FILES['image_file']['type']; $picfile_size = $_FILES['image_file']['size']; $picfile_temp = $_FILES['image_file']['tmp_name']; $dir = "files/uploads/" . $_SESSION[username]; if(empty($picfile_name)) { $error = "The name of the image was not found."; } if($picfile_size >= $max_space) { $error = "Image was too big!"; } if(! in_array($picfile_type, $files)) { $error = "File was not allowed! Only gif,png,jpg,jpeg!"; } if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) { $error = "Upload Error! (HACKER ATTACK!)"; } if(file_exists($dir.$picfile_name)) { $error = "A file with that name was already uploaded to your account!"; } if($error != '') { echo $error; exit(); } $ff = $dir . "/" . $picfile_name; if(move_uploaded_file($picfile_temp, $picfile_name)) { mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us/$ff','','','$_SESSION[id]')") or die(mysql_error()); echo '<font color="red">Image Upload Successful!!</font> <a href="imageUpload.php" class="blue">Refresh Page</a>'; } else { echo 'Could not upload file!'; exit(); } } else { ?><div id="form"> <b>Upload Form</b> <center> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>"> <p><input type="file" name="image_file" size="20" /></p> <p><input type="submit" value="-Upload-" name="action" /></p> </form> </center> </div> <?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 what do you mean by doesnt upload properly? not to the correct directory? doesnt even upload the picture? please specify your problemTed Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted January 3, 2007 Author Share Posted January 3, 2007 it uploads ot the wrong directory ... its supposed to up load to files/uploads/USERNAME .. but it uploads to the same directory as "files" .. not in that folder, but in the same place as the "files" folder Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 Try doing this:[code]if(!move_uploaded_file($orginalfile, $targetfile){echo "file upload failed...";}else{echo "upload successful";}[/code]try this if the above doesnt work:[code]$upload = move_uploaded_file($orginalfile, $targetfile).........//whatever action you want to do after thatif ($upload === false){echo "file upload failed";} else {echo "upload successful";}Try those, i am not sure if they will work or not, but give it a tryTed[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted January 3, 2007 Author Share Posted January 3, 2007 it says it works ... but it doesnt even upload the picture.. heres the code i have:[code]<?php if($_POST["action"] == "-Upload-") { unset($picfile_name); //Prevent from uploading Again! :P if(! isset($_FILES['image_file'])) { $error = "An image was not found."; } $max_space = 524288; //.5 mg $files = array("image/gif", // Gif "image/jpeg", // jpe jpeg jpg "png", // PNG ); $picfile_name = $_FILES['image_file']['name']; $picfile_type = $_FILES['image_file']['type']; $picfile_size = $_FILES['image_file']['size']; $picfile_temp = $_FILES['image_file']['tmp_name']; $dir = "/files/uploads/" . $_SESSION[username]; if(empty($picfile_name)) { $error = "The name of the image was not found."; } if($picfile_size >= $max_space) { $error = "Image was too big!"; } if(! in_array($picfile_type, $files)) { $error = "File was not allowed! Only gif,png,jpg,jpeg!"; } if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) { $error = "Upload Error! (HACKER ATTACK!)"; } if(file_exists($dir.$picfile_name)) { $error = "A file with that name was already uploaded to your account!"; } if($error != '') { echo $error; exit(); } $ff = $dir . "/" . $picfile_name;$upload = move_uploaded_file($picfile_temp, $picfile_name);if($upload){ mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us$ff','','','$_SESSION[id]')") or die(mysql_error()); echo '<font color="red">Image Upload Successful</font> <a href="imageUpload.php" class="blue">Refresh Page</a>'; } else { echo 'Could not upload file!'; exit(); } } else { ?><div id="form"> <b>Upload Form</b> <center> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>"> <p><input type="file" name="image_file" size="20" /></p> <p><input type="submit" value="-Upload-" name="action" /></p> </form> </center> </div> <?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 try this:[code]<?php if($_POST["action"] == "-Upload-") { unset($picfile_name); //Prevent from uploading Again! :P if(! isset($_FILES['image_file'])) { $error = "An image was not found."; } $max_space = 524288; //.5 mg $files = array("image/gif", // Gif "image/jpeg", // jpe jpeg jpg "png", // PNG ); $picfile_name = $_FILES['image_file']['name']; $picfile_type = $_FILES['image_file']['type']; $picfile_size = $_FILES['image_file']['size']; $picfile_temp = $_FILES['image_file']['tmp_name']; $dir = "/files/uploads/" . $_SESSION[username]; if(empty($picfile_name)) { $error = "The name of the image was not found."; } if($picfile_size >= $max_space) { $error = "Image was too big!"; } if(! in_array($picfile_type, $files)) { $error = "File was not allowed! Only gif,png,jpg,jpeg!"; } if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) { $error = "Upload Error! (HACKER ATTACK!)"; } if(file_exists($dir.$picfile_name)) { $error = "A file with that name was already uploaded to your account!"; } if($error != '') { echo $error; exit(); } $ff = $dir . "/" . $picfile_name;$upload = move_uploaded_file($picfile_temp, $picfile_name);if($upload === true){ mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us$ff','','','$_SESSION[id]')") or die(mysql_error()); echo '<font color="red">Image Upload Successful</font><a href="imageUpload.php" class="blue">Refresh Page</a>'; } else { echo 'Could not upload file!'; exit(); } } else { ?><div id="form"> <b>Upload Form</b> <center> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>"> <p><input type="file" name="image_file" size="20" /></p> <p><input type="submit" value="-Upload-" name="action" /></p> </form> </center> </div> <?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted January 3, 2007 Author Share Posted January 3, 2007 same thing .. it says it works .. but its uploading the picture to the same directory as the "files" folder. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 can you list out your directories so i have a picture of where things are, some thing like this:index.php/files//images/ Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 [code]<?php if($_POST["action"] == "-Upload-") { unset($picfile_name); //Prevent from uploading Again! :P if(! isset($_FILES['image_file'])) { $error = "An image was not found."; } $max_space = 524288; //.5 mg $files = array("image/gif", // Gif "image/jpeg", // jpe jpeg jpg "png", // PNG ); $picfile_name = $_FILES['image_file']['name']; $picfile_type = $_FILES['image_file']['type']; $picfile_size = $_FILES['image_file']['size']; $picfile_temp = $_FILES['image_file']['tmp_name']; $dir = "/files/uploads/" . $_SESSION[username]; if(empty($picfile_name)) { $error = "The name of the image was not found."; } if($picfile_size >= $max_space) { $error = "Image was too big!"; } if(! in_array($picfile_type, $files)) { $error = "File was not allowed! Only gif,png,jpg,jpeg!"; } if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) { $error = "Upload Error! (HACKER ATTACK!)"; } if(file_exists($dir.$picfile_name)) { $error = "A file with that name was already uploaded to your account!"; } if($error != '') { echo $error; exit(); } $ff = $dir . "/" . $picfile_name;$upload = move_uploaded_file($picfile_temp, $ff);if($upload === true){ mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us$ff','','','$_SESSION[id]')") or die(mysql_error()); echo '<font color="red">Image Upload Successful</font><a href="imageUpload.php" class="blue">Refresh Page</a>'; } else { echo 'Could not upload file!'; exit(); } } else { ?><div id="form"> <b>Upload Form</b> <center> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>"> <p><input type="file" name="image_file" size="20" /></p> <p><input type="submit" value="-Upload-" name="action" /></p> </form> </center> </div> <?php}?>[/code]tell me if worked... Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted January 3, 2007 Author Share Posted January 3, 2007 all my files are under a folder called "zycoworld" .. it goes:"root"/zycoworld/files/uploads/USERNAME/ Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 actually, change it to $ff, like the one above, I edited it Quote Link to comment Share on other sites More sharing options...
techiefreak05 Posted January 3, 2007 Author Share Posted January 3, 2007 i tried your edited code .. no luck .. in fact now it says CANNOT UPLOAD FILE Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 3, 2007 Share Posted January 3, 2007 okay, i see, i cant get it right... :-\Ted Quote Link to comment 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.