Jump to content

Recommended Posts

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.

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 by jazzman1

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!!

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 by jazzman1

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 by evo4ever

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 by jazzman1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.