hi, i already reach to the end of my project, however there are still minor features i want to add in for the upload. When the user upload their pictures, i need to create a folder for that particular user and store the picture inside, means different user for different folders. Below will be the code i attempt to do but seems unsuccessful.:

For the HTML script:

<form enctype="multipart/form-data" action="uploader" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="500000000" />
    <center><h1>Choose a file to upload: </h1></center>
	<center><input name="uploadedfile" type="file" value="<? echo $rows['username']; ?>"/><input type="submit" name="upload" id="upload" value="Upload File" /></center>
  </form>

For the php script:

<?php
mkdir("/".$username."/", 0700);
$target_path = "/".$username."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
	echo "<h1>The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded</h1>";
	echo "<h1><a href='claim_try.php'>Back to claim page.</a></h1>";
} else{
    echo "<h1>There was an error uploading the file, please try again!</h1>";
}
?>

In the php script, where is $username coming from ? Have a hidden variable in the upload form and pass the username. Check if that user already have a folder. If yes, copy the image, else, create a folder and copy it. What error are you getting ?

well, the username do pass to uploader.php..
i ady echo it and got value..

and below will be the error i received from the web hosting:

Warning: mkdir() [function.mkdir]: Permission denied in /home/a8937841/public_html/project/uploader.php on line 3

Warning: move_uploaded_file(/ccc/finall.PNG) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/a8937841/public_html/project/uploader.php on line 7

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpi2cRAx' to '/ccc/finall.PNG' in /home/a8937841/public_html/project/uploader.php on line 7

and the code shown in up0loader.php:

<?php
session_start();
mkdir("/".$_SESSION["username"]."/", 0777);
echo $_SESSION["username"];
$target_path = "/".$_SESSION["username"]."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
	echo "<h1>The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded</h1>";
	echo "<h1><a href='claim_try.php'>Back to claim page.</a></h1>";
} else{
    echo "<h1>There was an error uploading the file, please try again!</h1>";
}
?>

The problem is with the first warning you are getting. Thats the cause of the other 2 warnings.
Check if safe mode is off(in php.ini).
Try this.

mkdir($_SESSION["username"]."/", 0777);

Why do you need the "/" in mkdir ?

oh..becoz i tought there need a / for directory..and now i already change the permisson.Thanks..
However, i still got the error:
Warning: move_uploaded_file(/1111/finall.PNG) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/a8937841/public_html/project/uploader.php on line 7 and
Unable to move '/tmp/phpk77cea' to '/1111/finall.PNG' in /home/a8937841/public_html/project/uploader.php on line 7

which means

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
	echo "<h1>The file ".  basename( $_FILES['uploadedfile']['name'])....

the name used in HTML input is uploadedfile and i not sure about the tem_name...

Okay ! so you aren't getting mkdir error anymore. Now, thats some progress.

Print out $target_path. Check what's in it. Also, check the permissions on tmp directory. Print out $_FILES as well. Btw, $_FILES is the temporary name of the file you have uploaded.

well, i juz discover there's empty inside..
echo $target_path;
echo $_FILES ;

my HTML:

<form enctype="multipart/form-data" action="uploader.php" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="500000000" />
    <center><h1>Choose a file to upload: </h1></center>
	<center><input name="uploadedfile" type="file" value="<? echo $_SESSION["username"]; ?>"/><input type="submit" name="upload" id="upload" value="Upload File" /></center>
  </form>

hmm.. Btw, why do you have $_SESSION["username"] in

<input name="uploadedfile" type="file" value="<? echo $_SESSION["username"]; ?>"/>

Have this in uploader.php. print_r($_FILES); See what is being posted when you upload a file.

becoz there will be a list of users in the database, i need to assign the username that use the upload feature after they sign in..so i create separate folder for the different users..thats y the value will be the username variable. Iziit bout the web hosting problem? i already set the permission for tht particular folder....

You can have a hidden variable and pass the username in it. What did print_r($_FILES) return ?

oh..by the way...
it returns nothing...

Are you sure you have the form action correct ? In your first post, it was

action="uploader" method="post">

. Then its uploader.php.
I am not really sure about the exact problem. If it was a hosting problem, print_r($_FILES) would atleast list the file details you are trying to upload.

well, it is correct....
the directory successfully created, however the files cant upload in..
i am searching for other method....

Try out a simple upload script first. Just upload a file to some folder. If that works, then the problem is with your script and not the hosting company.

well, thanks, i had successfully used my method and solve. I juz store the path to the database. Thanks for guiding me along my way..thanks again...Nandri

Hmm.. congrats..

Cheers,
Naveen

well, thanks, i had successfully used my method and solve. I juz store the path to the database. Thanks for guiding me along my way..thanks again...Nandri

Hi fujilec,

I am currently doing my 1st project on PHP and face the same problem with you too. How did you solve your problem? Any advice to me?

hi guys,
how I can make directory (folder) in server with php script with persian alphabet langauge ?

if you can try for this script sure be find my problem ;

mkdir('تست');

it s mean make folder with test (تست ) name . but when create that you can see folder with this name ( طھط³طھ )

what is your answer ?

Regards

hi!i really need full coding regarding this problem...please..help me...... :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.