i want to upload multiple image in php.am getting image path like (image.jpg,image2.jpg,etc..).it is possible to split the path and upload each file to folder...can anyone help me with code.

Dani AI

Generated

As explained, the input is a single comma-separated string of image paths/URLs and, as noted, the first step is to split that string. A practical, safe flow is: split the CSV into entries, trim blanks, detect URL vs local path, fetch or copy each file into a dedicated uploads folder, validate the file really is an image, sanitize and give it a unique filename, then save and log the result.

Important checks and hardening: prefer cURL for remote downloads (timeouts, follow-redirects, SSL verification). Never trust file extensions alone — validate with getimagesize() or finfo_file(). Restrict allowed image types and maximum size. Sanitize basenames (remove path-traversal characters) and prepend uniqid() to avoid collisions. Keep uploads in a non-executable directory and set safe permissions. Always handle errors per-item (log and continue) rather than aborting the whole batch.

Example outline (split -> fetch/validate -> save):

<?php
$csv = 'http://example.com/img1.jpg, /path/to/local/img2.png';
$target = __DIR__ . '/uploads/';
if (!is_dir($target)) mkdir($target, 0755, true);

$items = array_filter(array_map('trim', explode(',', $csv)));
$allowed = ['jpg','jpeg','png','gif'];

foreach ($items as $item) {
    $isUrl = filter_var($item, FILTER_VALIDATE_URL) !== false;
    if ($isUrl) {
        // download to temp, validate, then move to $target
        // (use cURL with timeouts; check HTTP code; write to temp file)
    } else {
        // check file exists, validate with getimagesize(), then copy to $target
    }
    // sanitize basename, create uniqid() filename, set permissions, log outcome
}
?>

If images actually come from a browser form, use an HTML input type="file" name="images[]" multiple and iterate $_FILES, using move_uploaded_file() for safety. Common failures to investigate: disabled allow_url_fopen (use cURL instead), permission errors on the target folder, invalid image headers, or remote servers blocking requests — check PHP logs and curl_error() output.

Recommended Answers

All 2 Replies

Your question is not very clear. To answer the obvious question as to whether or not you can upload each file to a folder, then yes you can. I assume from your (ill-formed) question that you have both/all file names in a single string, but you need to "cut" them apart in order to process them separately?

yes,you are right..i have all image path(url) in a single string with comma..now i need to split and upload each image file.

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.