evo4ever Posted May 21, 2013 Share Posted May 21, 2013 Hey ppl its my first post here so here goes...Me and two of my friends are creating a website called Souljaz Studios and Im in the middle of making the Image Upload script and Im having problems with it without errors. Heres my code... function upload_image() { // chmod'd to eliminate any permission errors... chmod("/gallery/", 777); if($_FILES["file"]["error"] > 0) { print "Error: " . $_FILES["file"]["error"] . "<br>"; } else { // Display the $_FILES array. Everything checks out print_r(var_dump($_FILES)); print "</br></br>"; print "Upload: " . $_FILES["file"]["name"] . "<br>"; print "Type: " . $_FILES["file"]["type"] . "<br>"; print "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; print "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if(file_exists("/gallery/" . $_FILES["file"]["name"])) { print $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "/gallery/" . $_FILES["file"]["name"]); print "Image uploaded successfully!"; } } if(is_uploaded_file($_FILES["file"]["tmp_name"])) { print "</br>File Uploaded"; } else { print "</br>File NOT uploaded"; } } The file gets uploaded to the windows/temp folder but it wont successfully move it to the /gallery/ folder within wwwroot/ upload_image.php file.... <?php include("inc/functions.inc.php"); if(isset($_FILES["file"])) upload_image(); ?> <form action="upload_image.php" method="post" enctype="multipart/form-data" name="file"> <p> <label for="image">Image</label> <input type="file" name="file" id="file"> </p> <p> <input type="submit" name="upload" id="upload" value="Upload"> </p> </form> Im running IIS by the way. Any help greatly appreciated! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/ Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 (edited) Few questions: 1. Is the function upload_image() located inside inc/functions.inc.php? 2. The gallery is a part of the web root directory or the project folder? 3. When you include inc/functions.inc.php you have to point action of your html form (in case the function upload_image() is there) to the same file, so try that: <?php function upload_image() { // chmod'd to eliminate any permission errors... chmod("gallery/", 777); if($_FILES["file"]["error"] > 0) { print "Error: " . $_FILES["file"]["error"] . "<br>"; } else { // Display the $_FILES array. Everything checks out print_r(var_dump($_FILES)); print "</br></br>"; print "Upload: " . $_FILES["file"]["name"] . "<br>"; print "Type: " . $_FILES["file"]["type"] . "<br>"; print "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; print "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if(file_exists("gallery/" . $_FILES["file"]["name"])) { print $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "gallery/" . $_FILES["file"]["name"]); print "Image uploaded successfully!"; } } if(is_uploaded_file($_FILES["file"]["tmp_name"])) { print "</br>File Uploaded"; } else { print "</br>File NOT uploaded"; } } Edited May 21, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431398 Share on other sites More sharing options...
evo4ever Posted May 21, 2013 Author Share Posted May 21, 2013 1. Yes 2. Gallery is part of the web root folder 3. Ive got rid of the function upload_image() and put the code directly into the image_upload.php file, so im no longer using functions.inc.php. New code as follows... if(isset($_FILES["file"])) { chmod("gallery/", 777); if($_FILES["file"]["error"] > 0) { print "Error: " . $_FILES["file"]["error"] . "<br>"; } else { print_r(var_dump($_FILES)); print "</br></br>"; print "Upload: " . $_FILES["file"]["name"] . "<br>"; print "Type: " . $_FILES["file"]["type"] . "<br>"; print "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; print "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if(file_exists("gallery/" . $_FILES["file"]["name"])) { print $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "gallery/" . basename($_FILES["file"]["name"])); print "Image uploaded successfully!"; } } if(is_uploaded_file($_FILES["file"]["tmp_name"])) { print "</br>File Uploaded"; } else { print "</br>File NOT uploaded"; } } ?> <form action="upload_image.php" method="post" enctype="multipart/form-data" name="file"> <p> <label for="image">Image</label> <input type="file" name="file" id="file"> </p> <p> <input type="submit" name="upload" id="upload" value="Upload"> </p> </form> ... And im still getting the same problem!! Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431401 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 Go to the upload_image.php and give me the path of : // current directoryecho getcwd() . "\n"; The same of the gallery directory. Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431405 Share on other sites More sharing options...
evo4ever Posted May 21, 2013 Author Share Posted May 21, 2013 In upload_image.php it returned C:\inetpub\wwwroot In /gallery/test.php it returned C:\inetpub\wwwroot\gallery Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431407 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 (edited) Try this and give us the result if you get an error message: inc/functions.inc.php <?php function upload_image() { // chmod'd to eliminate any permission errors... chmod("/gallery/", 777); if($_FILES["file"]["error"] > 0) { print "Error: " . $_FILES["file"]["error"] . "<br>"; } else { // Display the $_FILES array. Everything checks out print_r(var_dump($_FILES)); print "</br></br>"; print "Upload: " . $_FILES["file"]["name"] . "<br>"; print "Type: " . $_FILES["file"]["type"] . "<br>"; print "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; print "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if(file_exists("/gallery/" . $_FILES["file"]["name"])) { print $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "/gallery/" . $_FILES["file"]["name"]); print "Image uploaded successfully!"; } } if(is_uploaded_file($_FILES["file"]["tmp_name"])) { print "</br>File Uploaded"; } else { print "</br>File NOT uploaded"; } } upload_image.php <?php error_reporting(-1); include("inc/functions.inc.php"); if(isset($_FILES["file"])) upload_image(); ?> <form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post" enctype="multipart/form-data" name="file"> <p> <label for="image">Image</label> <input type="file" name="file" id="file"> </p> <p> <input type="submit" name="upload" id="upload" value="Upload"> </p> </form> EDIT: Make sure that the path to your web root directory is "C:\inetpub\wwwroot", inside the config file of your web server! Edited May 21, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431408 Share on other sites More sharing options...
evo4ever Posted May 21, 2013 Author Share Posted May 21, 2013 (edited) Just tried and nothing, still the same as before. Have u only added error_reporting(-1); and $_SERVER["REQUEST_URI"] to the upload_image.php file? Did u not add anything to functions.inc.php? Didnt notice any admendments. Edited May 21, 2013 by evo4ever Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431409 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 Hm....I don't know, maybe the problem coming from IIS server, but I've never used it. Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431411 Share on other sites More sharing options...
evo4ever Posted May 21, 2013 Author Share Posted May 21, 2013 (edited) Would u say theres anything wrong with my code? because I cant EDIT: I am actually starting to blame IIS to be honest Edited May 21, 2013 by evo4ever Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431413 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 No. there is nothing wrong in your script and the paths are correct too. Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431414 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 EDIT: I am actually starting to blame IIS to be honest Most of the users here using Apache web server. If you want to get more effective help in the future just install it and switch them. Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431419 Share on other sites More sharing options...
evo4ever Posted May 21, 2013 Author Share Posted May 21, 2013 Ive fixed it!!! It was a permissions error!! I changed to full control permissions on the gallery folder and it worked lol Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431423 Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 (edited) By the way, In linux (unix) if want to change the permission recursively you need to add a "--recursive" flag. In php should be something like: chmod("/somedir/ --recursive", 755); // OR chmod("/somedir/", 755, "--recursive"); But I'm not sure just test it Edited May 21, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278244-php-upload-script-not-moving-file-please-help/#findComment-1431425 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.