HebleV HebleV - 3 years ago 158
PHP Question

Why are images being uploaded at wrong location?

I have a image upload function. I choose a photo from the system and a folder from the dropdown list (basically I have various folders to store images and thumbnails) and upload it. Locally, it works as expected but when I upload it into Godaddy server it is uploading into wrong location on Godaddy server

My local code for detecting path

$upload_img = cwUpload('fileToUpload','C:\xampp\htdocs\kWebsite\images\K website'."\\".$_POST["path"]."\\",'',TRUE,
'C:\xampp\htdocs\kWebsite\images\thumbs'."\\".$_POST["path"]."\\",'200','160');


Code for Godaddy server

$upload_img = cwUpload('fileToUpload','\home\gho\public_html\images\K website'."\\".$_POST["path"]."\\",'',TRUE,
'\home\gho\public_html\images\thumbs'."\\".$_POST["path"]."\\",'200','160');


The above code works but it uploads images in the general images folder rather than uploading into desired folder.

Answer Source

We can't tell you too much without knowing some examples of path and more examples of things like your restrictions on possible upload directories by your hosting provider.

However, one thing that did make me think this is a problem from your code is that you're defining your path with back slashes (\), not forward slashes (/), backslashes aren't the proper way to define a file path on *nix systems, as they use forward slashes.

eg: /path/to/some/file.txt is valid, however \path\to\some\file.txt is not valid.

Try changing it to use forward slashes and let me know if that worked or helped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download