I am trying to upload file on ftp.
here is my code
$jname= "Accounts of Biotechnology Research";
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
move_uploaded_file($_FILES["submission_file"]["tmp_name"], "/Trade/upload/$jname/" . $dup_name ); // line 67
Trade is a folder inside public_html folder.
When i am uploading a file it gives me a warning like,
Warning: mkdir() [function.mkdir]: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 63
Warning: move_uploaded_file(/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/my_username/public_html/Trade/upload.php on line 67
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phphZXp0O' to '/Trade/upload/Accounts of Biotechnology Research/76164762-sm.pdf' in /home/my_username/public_html/Trade/upload.php on line 67
First:
You have a space here mkdir('/Trade/upload/ '.$jname);
. Suppose you should have mkdir('/Trade/upload/'.$jname);
(same for is_dir)
Second:
Ensure that you can write into Trade/upload
directory.
Third (and I suppose that is the real problem):
It looks like you are trying to upload into a directory with full path:
/home/my_username/public_html/Trade/upload/
, but your code will try to create a directory with full path:
/Trade/upload/
.
You need to change
if (!is_dir('/Trade/upload/ '.$jname)) {
mkdir('/Trade/upload/ '.$jname); // line 63
}
to
if (!is_dir('upload/'.$jname)) {
mkdir('upload/'.$jname); // line 63 (or maybe there should be Trade/upload, but suppose current working dir will be /home/my_username/public_html/Trade, so only upload/)
}
Another option is to force mkdir
to create directories recursively:
mkdir('/Trade/upload/'.$jname, 0755, true);
But in that case, files will be uploaded into /Trade/upload/...
instead of /home/my_username/public_html/Trade/upload/...
There are two things you should be aware of based on the error messages you received. I'm guessing /Trade
isn't the root path on your machine since it's clear in the error that your actual path is /home/my_username/public_html/Trade/
, so the first adjustment should be
$root_path = "/home/my_username/public_html/Trade/upload/";
The second adjustment I'd suggest is that you avoid pathnames with space in them:
$jname= "Accounts of Biotechnology Research"; //could be changed to
$jname= "Accounts_of_Biotechnology_Research"; //$jname = str_replace(" ","-",$jname) OR
$jname= "Accounts-of-Biotechnology-Research"; //$jname = str_replace(" ","-",$jname)
Finally take note of the space character on the following lines, they affect you final result:
if (!is_dir('/Trade/upload/ '.$jname)) { //AND
mkdir('/Trade/upload/ '.$jname);
}
Note the [space] between upload/ '.$jname
in both strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With