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] Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/ 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 Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151931 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 Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151932 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] Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151940 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] Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151958 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] Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151962 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. Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151969 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/ Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151975 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... Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151979 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/ Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151981 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 Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151982 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 Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151987 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 Link to comment https://forums.phpfreaks.com/topic/32648-image-upload-script-issue/#findComment-151998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.