简体   繁体   中英

PHP move_uploaded_file is Not uploading Images when full web path is given in Unix system

My Following code is working fine when I set

$target = "size_images/14_20131216231522_cashew.jpg";

But Not Working in Actual php Code when full web address path is given though 777 Unix access is granted to system.

I am trying upload an image from SubDomain to Main Domain, So i need to give Full Path.

Page : http:// subdomain .examples.com/

Code:

$target = "http://examples.com/size_images/14_20131216231522_cashew.jpg";
move_uploaded_file($_FILES["item_image"]["tmp_name"],$target);

For your reference, following are values of above code line...

echo $_FILES["item_image"]["tmp_name"]; --> "/tmp/php6RNC28"

echo $target --> "http://examples.com/size_images/14_20131216231522_cashew.jpg"

Even tried with relative path instead of http, No luck : /home/direc/www/size_images

No use of placing error code. its not returning any error.

error_reporting(E_ERROR | E_PARSE);

Try this, You need to use only relative path instead of domain path. Domain path doesn't work

$target = "size_images/14_20131216231522_cashew.jpg";
move_uploaded_file($_FILES["item_image"]["tmp_name"],$target);

instead of ,

$target = "http://examples.com/size_images/14_20131216231522_cashew.jpg";
move_uploaded_file($_FILES["item_image"]["tmp_name"],$target);

Send a file via POST with cURL and PHP Ref: http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/

Try using:

$target = $_SERVER['DOCUMENT_ROOT']."/size_images/14_20131216231522_cashew.jpg";

If you want to upload from subdomain.mydomain.com to mydomain.com simply put the upload script on mydomain.com and then use a relative path.

You are misunderstanding how move-uploaded-file() works. It is similar to "File Save", namely you have to tell the PHP script a locally-writeable directory and file name where the file goes.

You mention you're trying to go from "subdomain" to "main domain"... if these two web urls are hosted on the same machine, this will be possible, you will just choose the directory that has the files for the "main domain" site.

It has to be a relative path.. absolute path would not work.

Also make sure that you know the difference between "/" and "./" But I would strongly recommend to either use configuration variables(in case of framework) OR constants to store file path.

Former point to root and later point to current directory..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM